mirror of
https://github.com/nim-lang/Nim.git
synced 2026-08-01 04:59:05 +00:00
Should fix https://github.com/nim-lang/Nim/blob/devel/tests/async/tasyncclosestall.nim (the flaky one) in CI. Previously CI was somehow slow enough to race on completion through multiple callback layers. Also increased the message size to hopefully fill the socket's buffer quicker
33 lines
759 B
Nim
33 lines
759 B
Nim
discard """
|
|
action: run
|
|
"""
|
|
|
|
import asyncdispatch, os
|
|
|
|
proc wrap(fut: Future[void]): Future[void] =
|
|
result = newFuture[void]("wrap")
|
|
let retFuture = result
|
|
fut.addCallback proc () =
|
|
if fut.failed:
|
|
retFuture.fail(fut.error)
|
|
else:
|
|
retFuture.complete()
|
|
|
|
block:
|
|
let root = newFuture[void]("root")
|
|
let wrapped = wrap(wrap(wrap(root)))
|
|
let completedBeforeDeadline = withTimeout(wrapped, 20)
|
|
|
|
# Completion has happened at the bottom of the future chain, but its
|
|
# callbacks cannot propagate until control reaches the dispatcher.
|
|
root.complete()
|
|
sleep(40)
|
|
|
|
doAssert waitFor(completedBeforeDeadline)
|
|
|
|
block:
|
|
var callbackRan = false
|
|
sleepAsync(0).addCallback proc () = callbackRan = true
|
|
poll(0)
|
|
doAssert callbackRan
|