Skip to content

Add optional CoroutineStart parameter to launchIn #2571

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

Closed
pacher opened this issue Mar 8, 2021 · 1 comment
Closed

Add optional CoroutineStart parameter to launchIn #2571

pacher opened this issue Mar 8, 2021 · 1 comment
Labels

Comments

@pacher
Copy link

pacher commented Mar 8, 2021

launchIn is a convenient shortcut, but can't be used if a start parameter of launch needs to be provided.
Shall we add an optional start to launchIn? I was wondering why not and why it is not already there.

My use case (probably similar to this):
I am not advanced user and trying to stay away from Unconfined and Undispatched, but I guess I am finally in a situation where I should use the latter.
I have a hot source which currently is still reactor Flux (not yet migrated to flow), let's call it flux.

flux()
   .asFlow()
   .onEach { ... }
   .launchIn(scope)

action()

Here action indirectly modifies the source flux. I need to be sure that by the time action is called subscription to source flux has happened and no emissions are lost between launch and action.
Do I understand correctly that I just need to launchIn(scope, start = CoroutineStart.UNDISPATCHED) to be safe?

@qwwdfsad qwwdfsad added the flow label Mar 12, 2021
@qwwdfsad
Copy link
Collaborator

Yes, UNDISPATHCED would do the trick as long as you don't have any non-trivial operators in between, e.g. buffer that actually launches a separate coroutine for flow collection.

Thanks for the use-case! I will close this as a duplicate of #1326, but will reconsider its status, keeping additional demand on it in mind

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants