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:
But instead it's:
If the two promises are resolved individually it works as expected. But for some reason, the storage argument in the before hook of the then1 (edit: meant then2) callback is {n: 1} when the 2nd promise is resolved from within the then1 callback.
I ran into an issue when resolving a promise from within the
thencallback of another promise. The issue can be recreated using the (over)simplified code below:I expect the output of this to be:
But instead it's:
If the two promises are resolved individually it works as expected. But for some reason, the
storageargument in thebeforehook of the(edit: meantthen1then2) callback is{n: 1}when the 2nd promise is resolved from within thethen1callback.