Grégory Lureau
02/15/2022, 8:19 AMfetch
and so requires AbortController/AbortSignal.turansky
02/15/2022, 10:43 AMGrégory Lureau
02/15/2022, 11:01 AMsuspend fun myWrappedMethod() = GlobalScope.promise {
val abortController = AbortController()
val signal = abortController.signal
val signalContainer = { signal } // Pseudo code, I presume I'll require a data class to match the typical usage
theTypescriptMethod(signalContainer)
}
I can declare external for AbortController/AbortSignal, but I've to plug a call to abortController.abort()
when the coroutines is cancelled. I can check from the coroutineContext the current state (isActive) but it means I'll need to use setTimeout every 100ms 😨 or is there a way to plug a callback on the cancellation in a better way?turansky
02/15/2022, 1:15 PMturansky
02/15/2022, 1:16 PMGrégory Lureau
02/15/2022, 3:30 PMcancellation == reject?No I'm thinking about Kotlin calling myWrapedMethod() (a suspend method) in a coroutine scope, and then cancelling the scope/job. I think it should trigger the AbortController.abort() method so that the webbrowser fetch method is cancelled. Also heavy code in the typescript method should be cancellation cooperative by checking the AbortSignal.isAborted frequently and stop working if required (by throwing an exception maybe?).
Grégory Lureau
02/15/2022, 8:54 PMonabort
should be a var if we want to attach a kotlin callback on it. (I copy-pasted the code so not a problem for me.)turansky
02/15/2022, 9:02 PMturansky
02/16/2022, 2:47 PMpre.300