Open
Description
Use-case
I'm writing a multiplatform library using coroutines and one of the targets is JS.
It is expected that the JS build of the library will be used from JS; as such, I expose "Async
" counterparts of functions of my library that launch coroutines as promises. For example, if I have the following suspend function:
public suspend fun doSomething() { ... }
I also expose, on the JS end, something like:
public fun doSomethingAsync(): Promise<Unit> = myScope.promise { doSomething() }
Calling doSomething
from Kotlin must be done within a coroutine that I can cancel, however, calling doSomethingAsync
from JS makes it difficult to cancel the coroutine without exposing JS users to coroutines (which I'd like to avoid).
Proposal
Make CoroutineScope.promise
return a CancellablePromise
(extending Promise
) with a cancel
method that can be used to cancel the launched coroutine.