Merge pull request #9642 from narimiran/callback-order

keep the order of the callbacks
This commit is contained in:
Dominik Picheta 2018-11-07 23:46:29 +00:00 • committed by GitHub
commit d0a02fe66b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 7 deletions

View file

@ -123,11 +123,17 @@ proc add(callbacks: var CallbackList, function: CallbackFunc) =
callbacks.function = function callbacks.function = function
assert callbacks.next == nil assert callbacks.next == nil
else: else:
let newNext = new(ref CallbackList) let newCallback = new(ref CallbackList)
newNext.function = callbacks.function newCallback.function = function
newNext.next = callbacks.next newCallback.next = nil
callbacks.next = newNext
callbacks.function = function if callbacks.next == nil:
callbacks.next = newCallback
else:
var last = callbacks.next
while last.next != nil:
last = last.next
last.next = newCallback
proc complete*[T](future: Future[T], val: T) = proc complete*[T](future: Future[T], val: T) =
## Completes ``future`` with value ``val``. ## Completes ``future`` with value ``val``.

View file

@ -1,8 +1,9 @@
discard """ discard """
exitcode: 0 exitcode: 0
output: '''3 output: '''
2
1 1
2
3
5 5
''' '''
""" """