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

Address eventloop's double registerCallback call when using promises.New #3180

Merged
merged 2 commits into from
Jul 10, 2023
Merged
Changes from 1 commit
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
Next Next commit
Address eventloop's double registerCallback call when using promises.New
  • Loading branch information
oleiade committed Jul 10, 2023
commit 3e75a810aa544d370d54b0ed61b400aa09dd8ff8
28 changes: 16 additions & 12 deletions js/promises/promises.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,22 @@ import (
// return promise
// }
func New(vu modules.VU) (p *goja.Promise, resolve func(result any), reject func(reason any)) {
p, resolve, reject = vu.Runtime().NewPromise()
p, resolveFunc, rejectFunc := vu.Runtime().NewPromise()
callback := vu.RegisterCallback()

return p, func(i interface{}) {
callback(func() error {
resolve(i)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So for future reference - the problem here was that resolve here is the same resolve we return - which is the function we in. So this just recurse inside itself.

return nil
})
}, func(i interface{}) {
callback(func() error {
reject(i)
return nil
})
}
resolve = func(result any) {
callback(func() error {
resolveFunc(result)
return nil
})
}

reject = func(reason any) {
callback(func() error {
rejectFunc(reason)
return nil
})
}

return p, resolve, reject
}