Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the resolution value of a chained Promise if a then handler doesn't return anything?

If a then handler has no return statement, the resulting chained promise takes on the value undefined in bluebird. But I cannot see anywhere that it is specified in Promises/A+ or anywhere? Can this behavior be counted on?

Here's a test program:

var Promise = require('bluebird');

var p = Promise.resolve('test');

p.then(function(s) {
    console.log('s1='+s);
    // no return
}).then(function(s) {
    // bluebird prints "undefined".  is this specified by a standard?
    console.log('s2='+s);
});
like image 706
dmansfield Avatar asked Feb 03 '16 16:02

dmansfield


1 Answers

Promises/A+ specifies to use the return value of a callback to resolve the promise.

Every function call that doesn't throw an exception (that has a "normal completion", in spec terms) does have such a return value. If a function execution doesn't encounter a return statement, this value will be undefined. This is made explicit in the spec in section 9.2.1.

like image 144
Bergi Avatar answered Sep 20 '22 00:09

Bergi