mapAsync
Applies the given transformation function transform to each value of the original Flow and emits the results. The processing of items in the flow is concurrent and limited by concurrency level.
The result flow emits the elements in an ordered manner.
Example usage:
flowOf(1, 2, 3)
.mapAsync(2) { it * 2 }
.collect { println(it) } // Prints 2, 4, 6
Return
A new flow with the transformed items.
Parameters
The maximum number of concurrent transformations.
The transformation function to apply to each item.
Applies the given transformation function transform to each value of the original Flow and emits the results. The concurrency is managed by an AsyncSemaphore created by the semaphore suspending function.
The result flow emits the elements in an ordered manner.
Example usage:
val customSemaphore: suspend CoroutineScope.() -> AsyncSemaphore = { AsyncSemaphore(this, 2) }
flowOf(1, 2, 3)
.mapAsync(customSemaphore) { it * 2 }
.collect { println(it) } // Prints the results in an unordered manner
Return
A new flow with the transformed items.
Parameters
The suspending function that creates an AsyncSemaphore.
The transformation function to apply to each item.
Transforms the elements of the iterable concurrently using the provided transform function.
Return
A List containing the results of applying transform to each element of the iterable.
Parameters
A suspend function to apply to each element of the iterable.
Transforms the elements of the iterable concurrently using the provided transform function with a specified concurrency limit.
Return
A List containing the results of applying transform to each element of the iterable.
Parameters
The maximum number of concurrent transformations.
A suspend function to apply to each element of the iterable.