Skip to content

Instantly share code, notes, and snippets.

@eric-romero
Created October 28, 2021 23:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eric-romero/b3a036c77e67205ba23f14f4d493d8d0 to your computer and use it in GitHub Desktop.
Save eric-romero/b3a036c77e67205ba23f14f4d493d8d0 to your computer and use it in GitHub Desktop.
class MyHybridExtension {
val job = SupervisorJob()
var scope = CoroutineScope(Dispatchers.IO + job)
@JavascriptInterface
fun getContact(contactId: String, callbackId: String) = scope.launch {
try {
val contact: String = fetchContact(contactId)
callback(callbackId, contact)
} catch (e: OutOfMemoryError) {
eventLogger.reportOOM()
callbackError(callbackId, e)
}
}
// Do work in a coroutineScope to avoid crashing the outer scope
suspend fun fetchContact(contactId: String): String = coroutineScope {
...
}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment