Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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")
- );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement