-
Notifications
You must be signed in to change notification settings - Fork 4
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
Prevent stackoverflow #23
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -251,7 +251,13 @@ namespace promises.internal | |
if storage = invalid then | ||
' unregister any observers on the promise to prevent multiple callbacks | ||
promises.internal.unobserveFieldScoped(promise, promises.internal.PromiseField.promiseState) | ||
promises.internal.observeFieldScoped(promise, promises.internal.PromiseField.promiseState, promises.internal.notifyListeners) | ||
promises.internal.observeFieldScoped(promise, promises.internal.PromiseField.promiseState, sub(event) | ||
'run the notification nexttick to prevent stackoverflow due to cascading promises all resolving in sequence | ||
promises.internal.delay(sub(context) | ||
promises.internal.notifyListeners(context.event) | ||
end sub, { event: event }) | ||
end sub) | ||
|
||
storage = { | ||
promise: promise | ||
thenListeners: [] | ||
|
@@ -482,7 +488,7 @@ namespace promises.internal | |
print "Crash during utils.delay:", e | ||
#end if | ||
end try | ||
m[delayId] = invalid | ||
m.delete(delayId) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unrelated to the main issue. I noticed these timer entries were never getting properly cleaned up, as they were only being set to invalid. This should clean up the |
||
end sub) | ||
|
||
timer.control = "start" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was the important piece here. This observer fires synchronously, which would then trigger upstream promises to also trigger synchronously (since they were all already marked resolved).
By adding a nexttick, it allows each promise's observers to run nexttick, breaking the stack chain.