A DSL-engine to turbo-charge your Kotlin development

Overall performance differences between low-level-coroutine approach vs. io.turbodsl is negligible.

Latest version: v1.2.4
build.gradle.kts

dependencies {

    implementation("io.turbodsl:io-turbodsl-core:1.2.4")

    :

}

It already includes these dependencies:

dependencies {

    api("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.9.0")

    api("org.jetbrains.kotlin:kotlin-reflect:2.0.21")

    api("org.jetbrains:annotations:26.0.1")

}

Writing asynchronous code using io.turbodsl is simple:

// Restrict all execution to 10 seconds.

TurboScope.execute(timeout = 10_000L) {

    // Execute 3 jobs in parallel, and retry up to 10 times.

    // Return empty-string after last retry failure.

    // Restrict each retry execution to 2 seconds.

    retry(retries = 10, timeout = 2_000L, default = Default.EmptyString) {

        async(

            // Cancel pending jobs on first failure

            asyncMode = AsyncScope.AsyncMode.CancelFirst,

            throwOnFailure = true,

            job1 = asyncJob<String>(timeout = 500L) { "job1" },

            job2 = asyncJob<String>(delay = 100L) { "job2" },

            job3 = asyncJob<String>(timeout = 1_000L) { "job3" },

        ) { _, r1, r2, r3 ->

            // Since `throwOnFailure` is true, then this block is executed only if all jobs are successful.

            "${r1.success()} ${r2.success()} ${r3.success()}"

        }

    }.let { data ->

        // Retry 3 more times, delaying 0.5, 1, 2 seconds respectively

        retry<String, String>(input = data, retries = 3, retryDelay = 500, retryDelayFactor = 2.0) {

            // Maps each character in parallel (0 means trigger as many coroutines as items in collection)

            input.toList().asyncMap(maxJobs = 0) {

                when (it) {

                    'j' -> 1

                    'o' -> 2

                    'b' -> 3

                    ' ' -> 0

                    else -> it

                }

            }.joinToString(separator = "-")

        }

    }

}.let {

    // Prints out: 1-2-3-1-0-1-2-3-2-0-1-2-3-3

    println("Result: $it")

}

Resources

(Github)

(Medium)

(Github)