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

Not calling `setGlobalDispatcher newDispatcher()` costs 500ms #6846

Closed
RedBeard0531 opened this issue Nov 30, 2017 · 3 comments

Comments

Projects
None yet
5 participants
@RedBeard0531
Copy link
Contributor

commented Nov 30, 2017

import asyncdispatch
import asyncfile

var asyncStdout = 1.AsyncFD.newAsyncFile()
proc doStuff: Future[void] {.async.} =
  await asyncStdout.write "hello world\n"

#setGlobalDispatcher newDispatcher() # magical Go Fast button!
waitFor doStuff()

time: 502ms
time with dispatcher: 2ms

@kvinwang

This comment has been minimized.

Copy link
Contributor

commented Dec 1, 2017

The iterator generated by async is:

  iterator doStuffIter245003(): FutureBase {.closure.} =
    var future245004 = asyncStdout.write "hello world\x0A"
    yield future245004
    future245004.read
    complete(retFuture245002)

But the future245004 completed immediately after asyncStdout.write.
Then the next yield will cause an extra polling, which will get nothing but 500ms timeout.
I guess the right code should looks like this:

  iterator doStuffIter245003(): FutureBase {.closure.} =
    var future245004 = asyncStdout.write "hello world\x0A"
    if not future245004.finished:
      yield future245004
    future245004.read
    complete(retFuture245002)
@yglukhov

This comment has been minimized.

Copy link
Member

commented Dec 1, 2017

Will be fixed by #6614

@dom96

This comment has been minimized.

Copy link
Member

commented Aug 22, 2018

This appears to be fixed now.

Reproduces in 0.17.2 but not 0.18.0 nor devel.

@dom96 dom96 closed this Aug 22, 2018

dom96 added a commit that referenced this issue Aug 22, 2018

dom96 added a commit that referenced this issue Aug 22, 2018

dom96 added a commit that referenced this issue Aug 23, 2018

Araq added a commit that referenced this issue Aug 23, 2018

Araq added a commit that referenced this issue Aug 23, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.