proposal-function-once
proposal-function-once copied to clipboard
What happens if subsequent calls occur before first call completes?
As the readme,
If subsequent calls somehow occur before the first call finishes executing, then the subsequent calls are synchronously blocked until the first call finishes.
It's not clear to me how it works, especially reenter/recursive case, could you explain some details? Thank you!
I haven’t thought about it too much, so I removed that part from the explainer and slides. We can bikeshed about this before it reaches Stage 2.
function g (x) { /* Recursive code */ }
const gOnce = g.once();
gOnce(); // What should happen?
function g (x) { /* Stuff that takes a long time */ }
const gOnce = g.once();
const promise0 = (async () => gOnce())();
const promise1 = (async () => gOnce())();
// What should happen?
For me looks like a way to prevent the race condition.