# OutcomeReceiverKt

Added in 1.8.0

*** ** * ** ***


```
public final class OutcomeReceiverKt
```

<br />

*** ** * ** ***

## Summary

| ### Public methods |
|---|---|
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/os/OutcomeReceiver.html<@https://developer.android.com/reference/androidx/annotation/NonNull R, @https://developer.android.com/reference/androidx/annotation/NonNull E>` | `@https://developer.android.com/reference/androidx/annotation/RequiresApi(value = 31) <R extends https://developer.android.com/reference/java/lang/Object.html, E extends https://developer.android.com/reference/java/lang/Throwable.html> https://developer.android.com/reference/androidx/core/os/OutcomeReceiverKt#(kotlin.coroutines.Continuation).asOutcomeReceiver()( @https://developer.android.com/reference/androidx/annotation/NonNull https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-continuation/index.html<@https://developer.android.com/reference/androidx/annotation/NonNull R> receiver )` Returns an `https://developer.android.com/reference/android/os/OutcomeReceiver.html` that will resume this `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-continuation/index.html` when an outcome is reported. |

## Public methods

### asOutcomeReceiver

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

```
@RequiresApi(value = 31)
public static final @NonNull OutcomeReceiver<@NonNull R, @NonNull E> <R extends Object, E extends Throwable> asOutcomeReceiver(
    @NonNull Continuation<@NonNull R> receiver
)
```

Returns an `https://developer.android.com/reference/android/os/OutcomeReceiver.html` that will resume this `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-continuation/index.html` when an outcome is reported.

Useful for writing `suspend` bindings to async Android platform methods that accept `https://developer.android.com/reference/android/os/OutcomeReceiver.html`:

```
public suspend fun FancinessManager.query(
    query: FancinessManager.Query
): FancinessManager.QueryResult = suspendCancellableCoroutine<QueryResult> { 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#queryAsync method as follows:
    queryAsync(
        query,
        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.asOutcomeReceiver()
    )
}
```