# RunnableKt

Added in 1.8.0

*** ** * ** ***


```
public final class RunnableKt
```

<br />

*** ** * ** ***

## Summary

| ### Public methods |
|---|---|
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Runnable.html` | `https://developer.android.com/reference/androidx/core/util/RunnableKt#(kotlin.coroutines.Continuation).asRunnable()(@https://developer.android.com/reference/androidx/annotation/NonNull https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-continuation/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html> receiver)` Returns a `https://developer.android.com/reference/java/lang/Runnable.html` that will resume this `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-continuation/index.html` when an operation completes and the returned `https://developer.android.com/reference/java/lang/Runnable.html`'s `https://developer.android.com/reference/java/lang/Runnable.html#run()` method is called. |

## Public methods

### asRunnable

Artifact: [androidx.core:core](https://developer.android.com/jetpack/androidx/releases/core) [View Source](https://cs.android.com/search?q=file:androidx/core/util/Runnable.kt+function:asRunnable)

```
public static final @NonNull Runnable asRunnable(@NonNull Continuation<Unit> receiver)
```

Returns a `https://developer.android.com/reference/java/lang/Runnable.html` that will resume this `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-continuation/index.html` when an operation completes and the returned `https://developer.android.com/reference/java/lang/Runnable.html`'s `https://developer.android.com/reference/java/lang/Runnable.html#run()` method is called.

Useful for writing `suspend` bindings to async Jetpack library methods that accept `https://developer.android.com/reference/java/lang/Runnable.html` as a completion callback for a one-time operation:

```
public suspend fun FancinessManager.setFanciness(
    fanciness: Float
): Unit = suspendCancellableCoroutine<Unit> { continuation ->

    // Any Android API that supports cancellation should be configured to propagate
    // coroutine cancellation as follows:
    val canceller = CancellationSignal()
    continuation.invokeOnCancellation { canceller.cancel() }

    // Invoke the FancinessManager#setFanciness method as follows:
    queryAsync(
        fanciness,
        canceller,
        // Use a direct executor to avoid extra dispatch. Resuming the continuation will
        // handle getting to the right thread or pool via the ContinuationInterceptor.
        Runnable::run,
        continuation.asRunnable()
    )
}
```