Coroutine-based worker pool for parallel batch processing with backpressure
implementation com.philiprehberger:worker-poolCoroutine-based worker pool for parallel batch processing with backpressure.
implementation("com.philiprehberger:worker-pool:0.2.0")
<dependency>
<groupId>com.philiprehberger</groupId>
<artifactId>worker-pool</artifactId>
<version>0.2.0</version>
</dependency>
import com.philiprehberger.workerpool.*
val results = workerPool<String, Int>(concurrency = 5) {
urls.forEach { url -> submit(url) { fetchSize(it) } }
onProgress { done, total -> println("$done/$total") }
}
// With per-task timeout
import kotlin.time.Duration.Companion.seconds
val results = workerPool<String, Int>(concurrency = 5, timeout = 10.seconds) {
urls.forEach { url -> submit(url) { fetchSize(it) } }
onError { url, e -> println("Failed: $url — ${e.message}") }
}
// Simple list parallel map
val sizes = urls.parallelMap(concurrency = 10) { fetchSize(it) }
| Function / Class | Description |
|---|---|
workerPool(concurrency, timeout?) { } | Process tasks with bounded parallelism and optional per-task timeout |
WorkerPoolScope.submit(input, task) | Submit a task |
WorkerPoolScope.onProgress { completed, total -> } | Progress callback |
List<T>.parallelMap(concurrency, transform) | Parallel list mapping |
./gradlew test
./gradlew build
If you find this project useful: