-
Notifications
You must be signed in to change notification settings - Fork 4
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
Fix: Parent Job is Cancelled #78
Conversation
Hello! My personal opinion so far is that both are pretty much the same, so what's currently in the PR is perfectly acceptable. After a simple test, they both solve the Do you have any thoughts on this? If you have room for more testing and comparison then I look forward to your results. |
|
||
private val CoroutineContext4Js: CoroutineContext = Dispatchers.Default | ||
private val CoroutineContext4Js: CoroutineContext = Dispatchers.Default + SupervisorJob() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any difference between using a custom scope and GlobalScope
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I tried to use GlobalScope, but it still threw the Parent job is Cancelled
exception. This only works with SupervisorJob()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay. The merged version has been released and you can try to update it now!
It doesn't seem like you have any more opinions. Then let's follow the current practice. |
Thanks! |
When using the plugin, I ran into a problem: when executing http requests to js in the suspend methods generated by the plugin, if there was any unprocessed error that led to the termination of the child job of the root, this led to the termination of all other jobs in this context. After that, when calling the same method, it threw an error: Parent Job is Cancelled. Using supervisor job in context helped me.
In Kotlin, a supervised coroutine scope is typically created to ensure that the failure of a child coroutine does not automatically cancel its sibling coroutines. This can be useful for specific structured concurrency needs.
Here’s how you can achieve a supervised coroutine scope:
Use
SupervisorJob
with your CoroutineScopeA SupervisorJob allows for the creation of a coroutine scope where child coroutines fail independently.
Create a scope with
SupervisorJob
You can create a CoroutineScope using a SupervisorJob combined with a Dispatcher (like Dispatchers.Default or
Dispatchers.IO
).