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

Execution of async code in a new thread #3

Closed
dzharkov opened this issue Jun 24, 2016 · 2 comments
Closed

Execution of async code in a new thread #3

dzharkov opened this issue Jun 24, 2016 · 2 comments
Labels

Comments

@dzharkov
Copy link
Contributor

In current implementation execution of coroutine code starts in the same thread and continues until first execution point.
Probably it's worth to run it on a thread-pool (it could be another parameter with some sensible default value, e.g. ForkJoinPool.commonPool())

@ilya-g
Copy link
Member

ilya-g commented Jul 7, 2016

It should be noted that in .NET async has similar behavior — it runs synchronously until the first await is encountered. It even can continue to execute synchronously in case if the awaitable being awaited is already completed. It all helps to minimize unnecessary thread switches.

In case if one needs to postpone the execution, it can be done with Task.Yield awaitable:

await Task.Yield()

@elizarov
Copy link
Contributor

The decision was to always require an explicit specification of execution policy for most coroutine builder. So launch(Here) { ... } would execute like in .NET (until first suspend), while launch (CommonPool) { ... } would immediate schedule into a background thread. Other execution policies can be defined by user. The only exception is a future { } which goes to CommonPool by default.

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

3 participants