-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Fixes #7758 #7759
Fixes #7758 #7759
Conversation
Looks good and will merge once tests pass. |
This fix is incredibly wrong.
|
Added the same fix for windows. |
@cheatfate, the problem you described indeed exists (for a long time already), however it is irrelevant to this fix. |
Immediately completed tasks, which will use |
@cheatfate, you could write a test case for that, and I could prove you the problem existed long before, and still exists. |
@cheatfate, ok don't bother. Here's a proof: import asynchttpserver, asyncdispatch, times
let s = newAsyncHttpServer()
proc handleClient(request: Request) {.async.} = discard
asyncCheck s.serve(Port(8080), handleClient)
let wait = sleepAsync(200)
waitFor(wait) # Wait a bit to let the server initialize
var startTime, endTime: float
let f = newFuture[void]()
f.callback = proc() =
endTime = epochTime()
echo "The message! It took us ", endTime - startTime, " seconds to display it"
f.complete()
echo "now you should immediately see the message..."
startTime = epochTime()
poll(2000) Outputs:
This code works equally the same with my pr or without it. EDIT: As a side note, this issue can be fixed by merging #6614... |
@cheatfate, you're probably right, but nevertheless this is out of the scope of this pr. |
@cheatfate, can you fix #7193? If yes, then please do. Otherwise I don't see how my |
I can't fix it easily. The easiest way to fix it is to revert all changes to If #7193 got fixed, then immediately completed Futures, e.g. tasks performing their job without any continuation will finish via callSoon(). And because callSoon() is working with loop.callbacks list, it will be processed after your ugly sleep(). So this simple example will finish after 10 seconds, but all other async world will finish it immediately: import asyncdispatch
proc task1() {.async.}
await sleepAsync(10000)
proc task2() {.async.} =
echo "This procedure must be completed immediately"
when isMainModule:
asyncCheck task1()
waitFor task2() |
Completes immediately for me. |
@dom96 it completes immediately now, because #7193 is not resolved/fixed.
|
I can see 2 simple ways of solving your problem.
|
This was fixed by @dom96 differently. Closing. |
No description provided.