File tree Expand file tree Collapse file tree
sdk-api-kotlin/src/main/kotlin/dev/restate/sdk/kotlin Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -29,7 +29,6 @@ import kotlin.jvm.optionals.getOrNull
2929import kotlin.time.Duration
3030import kotlin.time.toJavaDuration
3131import kotlinx.coroutines.*
32- import kotlinx.coroutines.future.await
3332
3433internal class ContextImpl
3534internal constructor (
Original file line number Diff line number Diff line change 99package dev.restate.sdk.kotlin
1010
1111import dev.restate.common.Slice
12+ import dev.restate.sdk.common.AbortedExecutionException
1213import dev.restate.sdk.endpoint.definition.HandlerContext
1314import dev.restate.serde.Serde
15+ import java.util.concurrent.CompletionStage
1416import kotlinx.coroutines.CancellationException
17+ import kotlinx.coroutines.future.await as kotlinxAwait
18+
19+ /* *
20+ * Awaits [this], translating the SDK-internal [AbortedExecutionException] control-flow signal into
21+ * a coroutine [CancellationException] (coroutine idiomatic way of initiating an abort).
22+ */
23+ internal suspend fun <T > CompletionStage<T>.await (): T =
24+ try {
25+ this .kotlinxAwait()
26+ } catch (e: AbortedExecutionException ) {
27+ throw CancellationException (" Restate invocation suspended or closed" ).apply { initCause(e) }
28+ }
1529
1630internal fun <T : Any ?> Serde<T>.serializeWrappingException (
1731 handlerContext : HandlerContext ,
Original file line number Diff line number Diff line change @@ -23,7 +23,6 @@ import kotlin.time.Duration
2323import kotlin.time.toJavaDuration
2424import kotlinx.coroutines.CoroutineScope
2525import kotlinx.coroutines.currentCoroutineContext
26- import kotlinx.coroutines.future.await
2726import kotlinx.coroutines.launch
2827
2928internal abstract class BaseDurableFutureImpl <T : Any ?> : DurableFuture <T > {
You can’t perform that action at this time.
0 commit comments