Skip to content

onceAsync #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
js-choi opened this issue Mar 30, 2022 · 1 comment
Open

onceAsync #8

js-choi opened this issue Mar 30, 2022 · 1 comment
Labels
question Further information is requested

Comments

@js-choi
Copy link
Collaborator

js-choi commented Mar 30, 2022

As #2 (comment) says, the plenary today was slightly in favor of once functions returning undefined every time (and ignoring arguments), so that all function calls remain idempotent. Any sync error thrown by the first call would only be thrown by the first call once and no more times after that. If the return value is needed, the developer would have to use a memoize function instead (which I also plan to propose).

However, returning undefined means that the promises returned by async functions are lost—which also means that rejections cannot be detected.

Should we have a onceAsync function? Is it within scope of this proposal?

If const f = onceAsync(Promise.resolve); then [f(0), f(1), f(2)] could return [p, p, p], where p is the same promise that resolves to undefined, and arguments are ignored.

(Spun off from #7.)

@js-choi js-choi added the question Further information is requested label Mar 30, 2022
@zloirock
Copy link

In case of returning a cached value, this issue disappears by itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants