Skip to content
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

Memoize on success only #1465

Closed
RandomSeeded opened this issue Aug 16, 2017 · 0 comments · Fixed by #1466
Closed

Memoize on success only #1465

RandomSeeded opened this issue Aug 16, 2017 · 0 comments · Fixed by #1466
Milestone

Comments

@RandomSeeded
Copy link

This would be a breaking change.

In today's world, if a memoized function errors on initial call, it will error on all future calls. I would have expected the memoization to only occur on success. This seems like a reasonable assumption given that a typical use-case for an async.memoize would be an external call.

Example case:

const getQueueUrl = async.memoize(function(queueName, cb) {
  async.waterfall([
    function(cb) {
      sqs.getQueueUrl(queueName, cb);
    },
    function({ QueueUrl }, cb) {
      cb(null, QueueUrl);
    },
  ], cb);
});

If the sqs queue has not been fully initialized by the time getQueueUrl is invoked initially, all future invocations of getQueueUrl will fail, even after the queue has been fully initialized.

I would be happy to either create a pull request to only memoize on success or update the documentation to clarify that the function will be memoized regardless of success or error.

@hargasinski hargasinski added this to the 3.0 milestone Sep 13, 2017
hzalaz added a commit to hzalaz/mongo-getdb that referenced this issue May 7, 2022
Includes a fix for memoize memoize no longer memoizes errors
(caolan/async#1465, caolan/async#1466)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants