From a52c2d9adb2b446e928151bfa5998fa45db10cd0 Mon Sep 17 00:00:00 2001 From: nathan Date: Wed, 12 Aug 2020 23:31:36 +0200 Subject: [PATCH] Added trampoline for coroutine suspend argument access --- .../network/other/SuspendFunctionAccess.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/dorkbox/network/other/SuspendFunctionAccess.java diff --git a/src/dorkbox/network/other/SuspendFunctionAccess.java b/src/dorkbox/network/other/SuspendFunctionAccess.java new file mode 100644 index 00000000..f77af43b --- /dev/null +++ b/src/dorkbox/network/other/SuspendFunctionAccess.java @@ -0,0 +1,24 @@ +package dorkbox.network.other; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import kotlin.coroutines.Continuation; +import kotlin.jvm.functions.Function1; + +/** + * Class to access suspending invocation of methods from kotlin... + * + * ULTIMATELY, this is all java bytecode, and the bytecode signature here matches what kotlin expects. The generics type information is + * discarded at compile time. + */ +public +class SuspendFunctionAccess { + @SuppressWarnings("unchecked") + @Nullable + public static + Object invokeSuspendFunction(@NotNull final Object suspendFunction, @NotNull final Continuation continuation) { + Function1, ?> suspendFunction1 = (Function1, ?>) suspendFunction; + return suspendFunction1.invoke((Continuation) continuation); + } +}