collect Single
inline fun <T : Any> collectSingle(noinline onResult: (result: T?, error: Throwable?) -> Unit, dispatcher: CoroutineDispatcher = Dispatchers.Default): DataCollector<T>
Creates and starts an DataCollector that collects exactly one time.
This is a convenience factory function for the most common use case of collecting a single set of asynchronous data.
Return
A new, active instance of DataCollector that will automatically cancel after one collection.
Parameters
T
The data class type to be collected and instantiated. It must be reified
.
on Result
The callback lambda that will be invoked once with the result or an error.
dispatcher
The CoroutineDispatcher
for the internal scope. Defaults to Dispatchers.Default
.
Throws
if the provided generic type T
is not a data class
.