Show HN: You can create promises in JavaScript without nesting
Imagine if you could write:
const [promise, resolve, reject] = await P();
// just use resolve() or reject() inline here
Well, now you can! Introducing... one weird trick: function P() {
let p;
return new Promise(function (resolve) {
p = new Promise(function (res, rej) {
resolve([p, res, rej]);
});
});
}