collect
Creates and starts an DataCollector for continuous or a specific number of collections.
This factory function provides a clean, type-safe API for creating a collector. Thanks to inline
and reified
, you can specify the target data class T
as a generic parameter (e.g., collect<EventsData>(...)
) without needing to pass the class reference (EventsData::class
) manually. This is the recommended way to create an instance.
Return
A new, active instance of DataCollector.
Parameters
The data class type to be collected and instantiated. It must be reified
.
The callback lambda that will be invoked for each successful collection or error.
The number of times to collect. Defaults to null
for continuous collection.
The CoroutineDispatcher
for the internal scope. Defaults to Dispatchers.Default
.
Throws
if the provided generic type T
is not a data class
.