Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
var longFn = function(x) {
return new Promise(function(res, rej) {
if (x) {
setTimeout(res(x), 1000);
} else {
rej("ERROR from not passing in a value to longFn");
}
});
};
async function f(inputToAsync) {
console.log("f() starting with param: ", inputToAsync);
let result;
try {
result = await longFn(inputToAsync);
} catch (err) {
console.log("THROWING err: " + err);
throw err;
}
return "RETURN VALUE FROM ASYNC function: " + inputToAsync;
}
var p = f("INPUT TO ASYNC FUNCTION");
console.log("1: return value of async function is ", p);
p.then(
res => console.log("1: FINISHED: got back: " + res)
).catch(
err => console.log("1: GOT ERROR: err")
);
var p = f(false);
console.log("2: return value of async function is ", p);
p.then(
res => console.log("2: FINISHED: got back: " + res)
).catch(
err => console.log("2: GOT ERROR: err")
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment