-
public class ContinueA static helper class allowing Java invocations to Kotlin coroutines a little easier on the eye. When invoking a suspending function in Java there is an extra parameter on the signature accepting a Continuation. Typically this would require creating an anonymous object to implement both Continuation.context and Continuation.resumeWith. This class allows you to accomplish the same thing with a more inline/lambda approach:
someSuspendingMethod(normalArg1, normalArg2, Continue.with(result -> { ... }))if you don't need to continue with anything you can simply use:
someSuspendingMethod(normalArg1, normalArg2, Continue.none())
-
-
Method Summary
Modifier and Type Method Description final static <R extends Any> Continuation<R>with(Consumer<ContinueResult<R>> onFinished, CoroutineContext context)Allows java code to provide a lambda as a continuation to a Kotlin coroutine. final static <R extends Any> Continuation<R>with(Consumer<ContinueResult<R>> onFinished)Allows java code to provide a lambda as a continuation to a Kotlin coroutine. final static <R extends Any> Continuation<R>none()Allows java code to indicate they have no follow-up to a Kotlin coroutine. -
-
Method Detail
-
with
@RequiresApi(value = 24)@JvmOverloads() final static <R extends Any> Continuation<R> with(Consumer<ContinueResult<R>> onFinished, CoroutineContext context)
Allows java code to provide a lambda as a continuation to a Kotlin coroutine.
- Parameters:
onFinished- Called when the coroutine has completed, passing in the result (ContinueResult) of the coroutine for the java code to continue processing.context- The optional coroutine context to run the onFinished lambda under.
-
with
@RequiresApi(value = 24)@JvmOverloads() final static <R extends Any> Continuation<R> with(Consumer<ContinueResult<R>> onFinished)
Allows java code to provide a lambda as a continuation to a Kotlin coroutine.
- Parameters:
onFinished- Called when the coroutine has completed, passing in the result (ContinueResult) of the coroutine for the java code to continue processing.
-
none
@JvmOverloads() final static <R extends Any> Continuation<R> none()
Allows java code to indicate they have no follow-up to a Kotlin coroutine.
-
-
-
-