diff --git a/compiler/src/main/kotlin/deezer/kustomexport/compiler/js/pattern/SharedTransformer.kt b/compiler/src/main/kotlin/deezer/kustomexport/compiler/js/pattern/SharedTransformer.kt index 4e239b5..dcd9bdc 100644 --- a/compiler/src/main/kotlin/deezer/kustomexport/compiler/js/pattern/SharedTransformer.kt +++ b/compiler/src/main/kotlin/deezer/kustomexport/compiler/js/pattern/SharedTransformer.kt @@ -141,11 +141,12 @@ fun FunctionDescriptor.buildWrappingFunctionBody( body += "val result = $callStr(" body += if (parameters.isNotEmpty()) "\n" else "" body += params - body += if (parameters.isNotEmpty()) ")\n" else ")\n" + body += if (parameters.isNotEmpty()) ")" else ")" + + body += if (import && isSuspend) ".%M()\n".toFormatString(coroutinesAwait) else "\n".toFormatString() body += if (import || !isSuspend) "returnĀ·" else "" body += returnType.portMethod(import, "result".toFormatString()) - body += if (import && isSuspend) ".%M()".toFormatString(coroutinesAwait) else "".toFormatString() if (!import && isSuspend) body += "\n}" return body diff --git a/samples/src/commonMain/kotlin/sample/coroutines/InterfaceWithSuspend.kt b/samples/src/commonMain/kotlin/sample/coroutines/InterfaceWithSuspend.kt new file mode 100644 index 0000000..f1e5db4 --- /dev/null +++ b/samples/src/commonMain/kotlin/sample/coroutines/InterfaceWithSuspend.kt @@ -0,0 +1,21 @@ +package sample.coroutines + +import deezer.kustomexport.KustomExport + +@KustomExport +interface IThingDoer { + suspend fun doThings(): List +} + +class NonWebThingDoer : IThingDoer { + override suspend fun doThings(): List { + return listOf(1, 2, 3) + } +} + +@KustomExport +class WebThingDoer : IThingDoer { + override suspend fun doThings(): List { + return listOf(3, 2, 1) + } +} diff --git a/samples/src/commonMain/kotlin/sample/coroutines/InterfaceWithSuspend.ts b/samples/src/commonMain/kotlin/sample/coroutines/InterfaceWithSuspend.ts new file mode 100644 index 0000000..adc154c --- /dev/null +++ b/samples/src/commonMain/kotlin/sample/coroutines/InterfaceWithSuspend.ts @@ -0,0 +1,12 @@ +import { runTest } from "../shared_ts/RunTest" +import { assert, assertEquals, assertQuiet, assertEqualsQuiet } from "../shared_ts/Assert" +import { sample } from '@kustom/Samples' + +runTest("InterfaceWithSuspend", async () : Promise => { + var neverAbortController = new AbortController() + var neverAbortSignal = neverAbortController.signal + + const thingDoer = new sample.coroutines.js.WebThingDoer() + const res = await thingDoer.doThings(neverAbortSignal) + assertEquals([3, 2, 1].join(","), res.join(","), "executes suspend function with JS friendly types") +})