Message from JavaScript discussions

January 2019

— Researcher's dream)

— 

const Halter = () => {
const waiting = [];
return {
hlt: () =>
new Promise(resolve =>
waiting.push(resolve)),
continue: (...a) =>
Promise.all(waiting.map(x =>
x(...a)))
};
};

const h = Halter();

async function foo() {
await h.hlt();
console.log('foo');
}

foo();
setTimeout(() => h.continue(), 1000);
// logs 'foo' after 1 sec

— How is that?

— Too complex

— Wat

— Where is the complexity even

— It's synthetic

— Look at the examples i made in PR

— You wait for event after you set it, and then it goes on

— class Halter {
constructor() {
this.waiting = [];
}
hlt() {
new Promise(resolve =>
this.waiting.push(resolve));
}
continue(...a) {
return Promise.all(this.waiting.map(x =>
x(...a)));
}
}

Message permanent page

— It works exactly like your example

— No, foo is called before