diff options
author | Araq <rumpf_a@web.de> | 2019-07-09 20:15:40 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2019-07-09 20:15:57 +0200 |
commit | 55e8aefbea2c6a152af903e60832a026b8bbf091 (patch) | |
tree | 1cbc7bdc1907edd7dac64c51643db5d26fd05973 /lib | |
parent | 73c570d1d99651b4f79a0bc5f7e10027e5b7208a (diff) | |
download | Nim-55e8aefbea2c6a152af903e60832a026b8bbf091.tar.gz |
newruntime: async progress
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pure/asyncfutures.nim | 32 | ||||
-rw-r--r-- | lib/pure/asyncmacro.nim | 4 |
2 files changed, 26 insertions, 10 deletions
diff --git a/lib/pure/asyncfutures.nim b/lib/pure/asyncfutures.nim index 4a80056e2..1243a17f2 100644 --- a/lib/pure/asyncfutures.nim +++ b/lib/pure/asyncfutures.nim @@ -144,16 +144,32 @@ proc checkFinished[T](future: Future[T]) = raise err proc call(callbacks: var CallbackList) = - var current = callbacks + when not defined(nimV2): + # strictly speaking a little code duplication here, but we strive + # to minimize regressions and I'm not sure I got the 'nimV2' logic + # right: + var current = callbacks + while true: + if not current.function.isNil: + callSoon(current.function) + + if current.next.isNil: + break + else: + current = current.next[] + else: + var currentFunc = unown callbacks.function + var currentNext = unown callbacks.next - while true: - if not current.function.isNil: - callSoon(current.function) + while true: + if not currentFunc.isNil: + callSoon(currentFunc) - if current.next.isNil: - break - else: - current = current.next[] + if currentNext.isNil: + break + else: + currentFunc = currentNext.function + currentNext = unown currentNext.next # callback will be called only once, let GC collect them now callbacks.next = nil diff --git a/lib/pure/asyncmacro.nim b/lib/pure/asyncmacro.nim index f48a18afb..8e537ac25 100644 --- a/lib/pure/asyncmacro.nim +++ b/lib/pure/asyncmacro.nim @@ -31,10 +31,10 @@ template createCb(retFutureSym, iteratorNameSym, proc identName {.closure.} = try: if not nameIterVar.finished: - var next = nameIterVar() + var next = unown nameIterVar() # Continue while the yielded future is already finished. while (not next.isNil) and next.finished: - next = nameIterVar() + next = unown nameIterVar() if nameIterVar.finished: break |