newruntime: async progress

(cherry picked from commit 55e8aefbea)
This commit is contained in:
Araq
2019-07-09 20:15:40 +02:00
committed by narimiran
parent 14c6e3a6ab
commit ab98141c75
3 changed files with 27 additions and 11 deletions

View File

@@ -154,7 +154,7 @@ type
uninit: IntSet # set of uninit'ed vars
uninitComputed: bool
const toDebug = ""
const toDebug = "" # "server_continue"
template dbg(body) =
when toDebug.len > 0:

View File

@@ -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)
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
if current.next.isNil:
break
else:
current = current.next[]
while true:
if not currentFunc.isNil:
callSoon(currentFunc)
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

View File

@@ -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