-
Notifications
You must be signed in to change notification settings - Fork 1.9k
How to express intersection of two CoroutineScopes? #814
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
Comments
There is no ready-to-use public API for that at the moment, as it raises lots of non-trivial questions with respect to the exception handling. Can you please, clarify your use-case. Why would exactly needed it? |
@elizarov
|
In IJ we use the following function for attaching a "fake" child: It repeats the original parent-child semantics w.r.t. exception handling. We need this to support project-level services provided by plugins. (Project x Plugin) scope should be cancelled when a project is closed, or when a plugin is unloaded. Both project and plugin scopes does not contain each other: the project can be closed without unloading of a plugin, and the plugin can be unloaded without closing the project. |
dovchinnikov I see that your API is based on the concept of "attaching" the scopes. This kind of method could, theoretically, be called at any time after the coroutine is launched or scope is created. However, in the example, the scope is being created and attached to parents at the same time. So, the question here is whether this is actually always the case that you know all the "parents" at the time the scope is created? It has important implications for the shape of the API. Let's start with a simpler example, where the two scopes that need to be connected for the purpose of suspending function calls. It happens in cases like this:
We don't have a good solution for the need of One potential solution to the problem that we've discussed in the past was two-pronged.
How is this relevant to the above comment? If we follow with the above plan, then instead of the following code:
We could have it supported with the syntax like this:
What do you think? P.S. Alternatively, we can simply access an optinal llist (or vargs) or |
@elizarov thank you for considering the issue and IJ approach. I can see that
I think
I think the path-of-least-surprise for
|
(The rest is my speculation and brainstorm dump) AFAIU
Perhaps, a separate function (name TBD) would make sense (this is how I thought the original
What if the intersection would be performed on scopes? This would unlock the following possible possible API shapes:
About context jobs I have a gut feeling that |
Yes. The ideal future state is when any code that passes So, here is the problem: how do we carefully migrate from today's state to this ideal future state? We need to somehow start giving a warning on any code that tries to pass coroutine context with a job as a parameter to those coroutine builder functions, so that we can later turn this warning into an error. But how do we even identify such code? That is the question. |
I want to use
CoroutineScope
that is only working when twoJob
s are active.Example
The text was updated successfully, but these errors were encountered: