Backwards compatibility stub module for kotlinx-coroutines JDK8 integration functionality, merged with core since 1.7.0
npx @tessl/cli install tessl/maven-org-jetbrains-kotlinx--kotlinx-coroutines-jdk8@1.10.0kotlinx-coroutines-jdk8 is a backwards compatibility stub module for Kotlin coroutines JDK8 integration functionality. Since version 1.7.0, the JDK8-specific functionality has been merged directly into the core kotlinx-coroutines library, making this package a transition module that maintains compatibility for existing projects by providing dependency access to the core JDK8 integration APIs.
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:1.10.2")Since this is a stub module, all JDK8 integration functionality is accessed through imports from the core kotlinx-coroutines library:
// CompletableFuture integration
import kotlinx.coroutines.future.*
// java.time integration
import kotlinx.coroutines.time.*
// Stream integration
import kotlinx.coroutines.stream.*
// Core coroutines functionality
import kotlinx.coroutines.*The most common use case is converting between coroutines and CompletableFuture:
import kotlinx.coroutines.*
import kotlinx.coroutines.future.*
import java.util.concurrent.CompletableFuture
// Start a coroutine and get CompletableFuture
val scope = CoroutineScope(Dispatchers.Default)
val future: CompletableFuture<String> = scope.future {
delay(1000)
"Hello from coroutine!"
}
// Convert CompletableFuture to Deferred
val deferred: Deferred<String> = future.asDeferred()
// Await CompletableFuture in suspending context
suspend fun example() {
val result = future.await()
println(result)
}This stub module provides access to three main integration areas:
All functionality is implemented in the core kotlinx-coroutines library and accessed transitively through this dependency.
Bidirectional conversion between coroutines and Java's CompletableFuture/CompletionStage.
/**
* Starts a coroutine and returns its result as CompletableFuture
*/
fun <T> CoroutineScope.future(
context: CoroutineContext = EmptyCoroutineContext,
start: CoroutineStart = CoroutineStart.DEFAULT,
block: suspend CoroutineScope.() -> T
): CompletableFuture<T>
/**
* Converts Deferred to CompletableFuture
*/
fun <T> Deferred<T>.asCompletableFuture(): CompletableFuture<T>
/**
* Converts Job to CompletableFuture<Unit>
*/
fun Job.asCompletableFuture(): CompletableFuture<Unit>
/**
* Converts CompletionStage to Deferred
*/
@Suppress("DeferredIsResult")
fun <T> CompletionStage<T>.asDeferred(): Deferred<T>
/**
* Suspending await for CompletionStage
*/
suspend fun <T> CompletionStage<T>.await(): TAdapter methods that accept java.time.Duration parameters for coroutine timing functions.
/**
* java.time adapter for delay function
*/
suspend fun delay(duration: Duration): Unit
/**
* java.time adapter for withTimeout
*/
suspend fun <T> withTimeout(
duration: Duration,
block: suspend CoroutineScope.() -> T
): T
/**
* java.time adapter for withTimeoutOrNull
*/
suspend fun <T> withTimeoutOrNull(
duration: Duration,
block: suspend CoroutineScope.() -> T
): T?
/**
* java.time adapter for Flow.debounce
*/
@FlowPreview
fun <T> Flow<T>.debounce(timeout: Duration): Flow<T>
/**
* java.time adapter for Flow.sample
*/
@FlowPreview
fun <T> Flow<T>.sample(period: Duration): Flow<T>
/**
* java.time adapter for SelectBuilder.onTimeout
*/
fun <R> SelectBuilder<R>.onTimeout(
duration: Duration,
block: suspend () -> R
): UnitConvert Java 8 Streams to Kotlin Flows for seamless integration.
/**
* Converts Stream to Flow and closes the stream afterwards
*/
fun <T> Stream<T>.consumeAsFlow(): Flow<T>All types are defined in the core kotlinx-coroutines library:
// From kotlinx.coroutines
interface Job : CoroutineContext.Element
interface Deferred<out T> : Job
class CoroutineScope(context: CoroutineContext)
enum class CoroutineStart
interface CoroutineContext
// From kotlinx.coroutines.flow
interface Flow<out T>
interface FlowCollector<in T>
// From kotlinx.coroutines.selects
interface SelectBuilder<in R>
// Java types (from JDK)
class CompletableFuture<T>
interface CompletionStage<T>
interface Stream<T>
class Durationmodule kotlinx.coroutines.jdk8 {})