thunky-map

A map version of thunky

MIT 2 个版本
安装
npm install thunky-map
yarn add thunky-map
pnpm add thunky-map
bun add thunky-map
README

thunky-map

A map version of thunky

npm install thunky-map

Usage

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) {
  // ...
})

API

m = new ThunkyMap(load)

Make a new ThunkyMap instance. load should be a function taking a key and callback argument and should return a value.

m.get(key, cb)

Get a key. Triggers the load if the key hasn't been loaded before.

m.delete(key)

Delete a value

m.has(key)

Check if the map has a value

License

MIT

版本列表
1.0.1 2020-03-25
1.0.0 2020-03-10