Skip to content

Instantly share code, notes, and snippets.

@KoryNunn
Created September 19, 2018 03:35
Show Gist options
  • Save KoryNunn/c7282218e5f0b90a5f7e7d1bb4ff0e01 to your computer and use it in GitHub Desktop.
Save KoryNunn/c7282218e5f0b90a5f7e7d1bb4ff0e01 to your computer and use it in GitHub Desktop.
function getValue(){
return new Promise(function(resolve, reject){
reject('fail');
});
}
function doX(){
var x = getValue();
return new Promise(function(resolve, reject){
setTimeout(function(){
x.then(resolve).catch(reject);
});
});
}
doX().then(console.log).catch(console.log);
@KoryNunn
Copy link
Author

Oh yeah and this absolutely fails using async/await too:

function getValue(){
    return new Promise(function(resolve, reject){
        reject('fail');
    });
}

async function doX(){
    var x = getValue();
    var y = getValue();

    return await x + await y;
}

doX().then(console.log).catch(console.log);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment