Created
October 28, 2021 23:50
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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