Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add native coroutines example #72

Merged
merged 2 commits into from
Aug 11, 2021
Merged

Add native coroutines example #72

merged 2 commits into from
Aug 11, 2021

Conversation

AAkira
Copy link
Owner

@AAkira AAkira commented Aug 11, 2021

closes #56, #69

Run background thread

You can use this library on a background thread on iOS using Kotlin.coroutines as native-mt.

  • Define scope
internal val mainScope = SharedScope(Dispatchers.Main)

internal val backgroundScope = SharedScope(Dispatchers.Default)

internal class SharedScope(private val context: CoroutineContext) : CoroutineScope {
    private val job = Job()
    private val exceptionHandler = CoroutineExceptionHandler { _, throwable ->
        println("[Coroutine Exception] $throwable")
    }

    override val coroutineContext: CoroutineContext
        get() = context + job + exceptionHandler
}
  • usage
backgroundScope.launch {
    suspendFunction()
}

@AAkira AAkira merged commit 1587c27 into dev/2.0.0 Aug 11, 2021
@AAkira AAkira deleted the native-coroutines branch August 17, 2021 02:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant