W3cubDocs

/Bluebird

.return

.return(any value) -> Promise
.thenReturn(any value) -> Promise

Convenience method for:

.then(function() {
   return value;
});

in the case where value doesn't change its value because its binding time is different than when using a closure.

That means value is bound at the time of calling .return so this will not work as expected:

function getData() {
    var data;

    return query().then(function(result) {
        data = result;
    }).return(data);
}

because data is undefined at the time .return is called.

Function that returns the full path of the written file:

var Promise = require("bluebird");
var fs = Promise.promisifyAll(require("fs"));
var baseDir = process.argv[2] || ".";

function writeFile(path, contents) {
    var fullpath = require("path").join(baseDir, path);
    return fs.writeFileAsync(fullpath, contents).return(fullpath);
}

writeFile("test.txt", "this is text").then(function(fullPath) {
    console.log("Successfully file at: " + fullPath);
});

For compatibility with earlier ECMAScript version, an alias .thenReturn is provided for .return.

© 2013–2018 Petka Antonov
Licensed under the MIT License.
http://bluebirdjs.com/docs/api/return.html