janvladimirmostert
01/09/2022, 8:17 PM@JsName("blah2")
suspend fun blah2() {
should I GlobalScope its insides or is there a cleaner way?
@JsName("blah2")
fun blah2() {
GlobalScope.launch {
flow.collect {
println(it)
}
}
}
ephemient
01/09/2022, 8:38 PMfun jsBlah() = promise { kotlinSuspendBlah() }
janvladimirmostert
01/09/2022, 8:50 PMval coroutinesVersion = "1.6.0"
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion")
in my commonMain and that promise
does not appear in the autocomplete
I have
import kotlinx.coroutines.promise
and
CoroutineScope.promise { }
but that promise is not resolvingjanvladimirmostert
01/09/2022, 9:02 PMephemient
01/09/2022, 9:05 PMjanvladimirmostert
01/09/2022, 9:13 PMephemient
01/09/2022, 9:21 PMGlobalScope.promise {}
would be fairly equivalent to GlobalScope.launch {}
but returning a Promise
that JS can work withjanvladimirmostert
01/09/2022, 9:26 PMjanvladimirmostert
01/09/2022, 9:38 PMfun <T> promise(
context: CoroutineContext = EmptyCoroutineContext,
start: CoroutineStart = CoroutineStart.DEFAULT,
block: suspend CoroutineScope.() -> T,
): Promise<T> = CoroutineScope(context).async(context, start, block).asPromise()
Now this works correctly:
@JsName("doSomething")
fun doSomething() = promise {
state.emit(null)
""
}