async: minor refactorings (#15354)

This commit is contained in:
Andreas Rumpf 2020-09-18 11:22:34 +02:00 • committed by GitHub
commit 2671efab78
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 43 additions and 62 deletions

View file

@ -157,33 +157,15 @@ proc checkFinished[T](future: Future[T]) =
raise err
proc call(callbacks: var CallbackList) =
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 currentFunc.isNil:
callSoon(currentFunc)
if currentNext.isNil:
break
else:
currentFunc = currentNext.function
currentNext = unown currentNext.next
var current = callbacks
while true:
if not current.function.isNil:
callSoon(current.function)
if current.next.isNil:
break
else:
current = current.next[]
# callback will be called only once, let GC collect them now
callbacks.next = nil
callbacks.function = nil