All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.DataLoaderOptions.kt Maven / Gradle / Ivy

The newest version!
package io.fluidsonic.dataloader

import kotlinx.coroutines.*


public data class DataLoaderOptions internal constructor(
	val batch: Boolean,
	val batchScheduleFunction: DataLoader. (scope: CoroutineScope, callback: suspend () -> Unit) -> Unit,
	val cache: Boolean,
	val cacheKeyFunction: DataLoader.(key: Key) -> CacheKey,
	val cacheMap: DataLoaderCacheMap>>?,
	val maximumBatchSize: Int,
) {

	init {
		require(maximumBatchSize > 0) { "'maximumBatchSize' must be positive: $maximumBatchSize" }
	}


	public companion object
}


public fun  DataLoader.Companion.options(
	batch: Boolean = true,
	batchScheduleFunction: DataLoader.(scope: CoroutineScope, callback: suspend () -> Unit) -> Unit = DataLoaderImpl.defaultBatchScheduleFunction,
	cache: Boolean = true,
	cacheMap: DataLoaderCacheMap>>? = DataLoader.cacheMap(),
	maximumBatchSize: Int = Int.MAX_VALUE,
): DataLoaderOptions =
	options(
		batch = batch,
		batchScheduleFunction = batchScheduleFunction,
		cache = cache,
		cacheKeyFunction = { it },
		cacheMap = cacheMap,
		maximumBatchSize = maximumBatchSize,
	)


public fun  DataLoader.Companion.options(
	batch: Boolean = true,
	batchScheduleFunction: DataLoader. (scope: CoroutineScope, callback: suspend () -> Unit) -> Unit = DataLoaderImpl.defaultBatchScheduleFunction,
	cache: Boolean = true,
	cacheKeyFunction: DataLoader.(key: Key) -> CacheKey,
	cacheMap: DataLoaderCacheMap>>? = DataLoader.cacheMap(),
	maximumBatchSize: Int = Int.MAX_VALUE,
): DataLoaderOptions =
	DataLoaderOptions(
		batch = batch,
		batchScheduleFunction = batchScheduleFunction,
		cache = cache,
		cacheKeyFunction = cacheKeyFunction,
		cacheMap = cacheMap,
		maximumBatchSize = maximumBatchSize,
	)




© 2015 - 2025 Weber Informatics LLC | Privacy Policy