Message from JavaScript discussions

January 2019

— Would work

— 

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

— There, need to clear waiting processes when I run continue

— Don't even need Promise.all :P

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

Message permanent page

— This should do

— halt : () -> Promise<void>
continue : () -> Number (continued processes)

— Easy peasy

— Can even pass args to continue, in order to return a value from halt

— const Halter = () => {
const waiting = [];
return {
hlt: () =>
new Promise(resolve =>
waiting.push(resolve)),
continue: x =>
waiting
.splice(0, Infinity)
.map(f =>
f(x))
.length
};
};

Message permanent page

— (Didn't need spread)

— Https://github.com/nodejs/node/issues/25348

determin1st