A map version of thunky
npm install thunky-map
const ThunkyMap = require('thunky-map')
const m = new ThunkyMap(function (key, cb) {
// load the resource async
// only ran once per key
setTimeout(function () {
cb(null, key)
}, 1000)
})
// triggers the load function above
m.get('hi', function (err, val) {
// ...
})
// does not as it's already running
m.get('hi', function (err, val) {
// ...
})
Make a new ThunkyMap instance. load should be a function taking a key and callback argument and should return a value.
Get a key. Triggers the load if the key hasn't been loaded before.
Delete a value
Check if the map has a value
MIT