Skip to content

Memoize on success only #1465

@RandomSeeded

Description

@RandomSeeded

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.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions