export function x(y) {
let isBusy = false;
let currentPromise;
return () => {
if (!isBusy) {
isBusy = true;
currentPromise = y()
[Link](() => (isBusy = false));
}
return currentPromise;
};
}
function sleepAndLog(timeout) {
return new Promise(resolve => {
setTimeout(() => {
[Link]("hello world");
resolve();
}, timeout);
});
}
function sleepAndLog2() {
return new Promise(resolve => {
setTimeout(() => {
[Link]("hello world 2");
resolve();
}, 2000);
});
}
sleepAndLog()
sleepAndLog() // both after 2s
let sleepAndLogFn; = x(sleepAndLog);
sleepAndLogFn();
sleepAndLogFn(); // both at 2
[Link]("This should print before hello world");