git ssb

1+

cel / asyncmemo



Branch:
cel committed 1.3.1Latest: 0d09215 on 3/15/2020, 5:25:10 PM
📄README.md
📄index.js
📄package.json
📄test.js
README.md

asyncmemo

Memoize asynchronous function calls. Combine multiple calls with the same argument so that the underlying function is only called once for that argument. Optionally cache the result for that argument.

Install

npm install --save asyncmemo

Example

var asyncMemo = require('asyncmemo')
var xhr = require('xhr')
var get = asyncMemo(function (base, path, cb) {
  xhr.get(base + path, cb)
}, 'http://localhost')
get('/foo', function (err, resp) {
  console.log(err, resp)
})

API

asyncMemo([opts,] fn, [args...]): memo

A custom cache object can be passed using the cache option. This should have has, get, and set methods.

If you want to be able to use memoize a key that is not a string or number, you can specify a asString function to convert the key argument to a string.

License

Copyright (c) 2016-2020 Charles E. Lehner

Copying and distribution of this file, with or without modification, are permitted in any medium without royalty provided the copyright notice and this notice are preserved. This file is offered as-is, without any warranty.

Built with git-ssb-web