I'm completely rewriting my question do boil it down even further.
Why, in the following code, does x()
equate to undefined
instead of success
which is logged to the console by console.log('success');
The last line finishes executing in the console; then the .then()
call back is triggered.
How can I make it so x()
returns the 'success' value before the last line begins to execute.
Even yF() evaluates to undefined
. However, .then() is echoing th y: success
.
const promise = require('promise');
const requestify = require('requestify');
function x() {
requestify.get('https://<redacted>/')
.then(function (d) {
console.log('success', d.code);
return 'success';
})
.fail(function (f) {
console.log('fail', f.code);
return 'fail';
});
;
}
var yF = function () {
yP .then(function (th) { console.log("th", th); return th; })
.catch(function (fl) { console.log("fl", fl); return fl; });
}
var yP = new Promise(
function (resolve, reject) {
if (1 == 1) {
resolve("y: success");
} else {
reject(new Error("y: fail"));
}
}
);
console.log("hello", x());
console.log("world", yF());