proposal-function-once icon indicating copy to clipboard operation
proposal-function-once copied to clipboard

What happens if subsequent calls occur before first call completes?

Open hax opened this issue 3 years ago • 2 comments

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!

hax avatar Mar 19 '22 02:03 hax

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?

js-choi avatar Mar 19 '22 14:03 js-choi

For me looks like a way to prevent the race condition.

VitorLuizC avatar Mar 21 '22 19:03 VitorLuizC