node.js - Unexpected promise value in .then() -
i've inherited code , includes i've never seen before. after poking around, haven't found seems sufficiently explain i'm seeing.
doathingthatreturnsapromise() .then(currentstate => { ... return token.save({ key1: val1, key2: 'val2' }); }) .then(() => { console.log(arguments); }); token.save() returns resolved promise no value (e.g. return promise.resolve().
what surprised me that, in second .then(), arguments has value , it's value of currentstate. i've never bumped before , haven't found documentation indicates expected situation if empty resolution passed.
can shed light or point me bit of documentation sets expectation? since didn't expect it, want sure document or, if it's kind of accidental side effect, change things around bit.
this not normal behavior native js promises.
promise.resolve('a') .then(function() { return promise.resolve() }) .then(function() { console.log(arguments) }) my guess doathingthatreturnsapromise() returns non-standard promise. try wrapping in promise.resolve:
promise.resolve(doathingthatreturnsapromise()) .then(currentstate => { ... return token.save({ key1: val1, key2: 'val2' }); }) .then(() => { console.log(arguments); }); this behavior disappear.
Comments
Post a Comment