Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

keep the order of the callbacks #9642

Merged
merged 1 commit into from
Nov 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions lib/pure/asyncfutures.nim
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,17 @@ proc add(callbacks: var CallbackList, function: CallbackFunc) =
callbacks.function = function
assert callbacks.next == nil
else:
let newNext = new(ref CallbackList)
newNext.function = callbacks.function
newNext.next = callbacks.next
callbacks.next = newNext
callbacks.function = function
let newCallback = new(ref CallbackList)
newCallback.function = function
newCallback.next = nil

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) =
## Completes ``future`` with value ``val``.
Expand Down
5 changes: 3 additions & 2 deletions tests/async/tcallbacks.nim
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
discard """
exitcode: 0
output: '''3
2
output: '''
1
2
3
5
'''
"""
Expand Down