-
Notifications
You must be signed in to change notification settings - Fork 41
Open
Description
I ran into an issue when resolving a promise from within the then callback of another promise. The issue can be recreated using the (over)simplified code below:
require('async-listener')
var cls = {n: 0}
process.addAsyncListener({
create: function () {
return {n: cls.n}
},
before: function (context, storage) {
cls.n = storage.n
}
})
var resolve
cls.n = 1
Promise.resolve().then(function then1 () {
process._rawDebug('then1:', cls.n)
resolve()
})
cls.n = 2
new Promise(function (_resolve) {
resolve = _resolve
}).then(function then2 () {
process._rawDebug('then2:', cls.n)
})I expect the output of this to be:
then1: 1
then2: 2
But instead it's:
then1: 1
then2: 1
If the two promises are resolved individually it works as expected. But for some reason, the storage argument in the before hook of the (edit: meant then1then2) callback is {n: 1} when the 2nd promise is resolved from within the then1 callback.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels