Created
May 18, 2018 15:56
-
-
Save handicraftsman/a2a365d07845a6256a86395b319d353f to your computer and use it in GitHub Desktop.
asyncNew
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = (obj, ...args) => { | |
return new Promise((res, rej) => { | |
try { | |
res(new obj(...args)); | |
} catch (e) { | |
rej(e); | |
} | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const asyncNew = require('./asyncNew'); | |
asyncNew(Set, [1,2,3,4,5,6,7,8]).then(set => { | |
console.log(set); | |
}); |
Well, await async new
is verbose, but still a nice idea imo.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I would like to see this in js as a part of syntax though: