0.1.1 • Published 6 years ago

pregen-stash v0.1.1

Weekly downloads
3
License
MIT
Repository
github
Last release
6 years ago

pregen-stash

build status AppVeyor Build Status


FIFO data structure that serves you with pregenerated values from your custom computation-intensive function. Getting those pregenerated values then boils down to a cheap Array.prototype.pop.


Get it!

npm install --save pregen-stash

Usage

const createStash = require('pregen-stash')

createStash(5, Math.random)
  .then(stash => {
    for (var i = 0; i < 13; i++) console.log(stash.pop(), stash.size)
  })
  .catch(console.error)

API

createStash(size, gen)

Create a new Stash instance. size indicates the number of items that should be kept readily available at any time. gen must be a function. Its return values will be used to reup the stash. gen must have arity 0. createStash returns a Promise that resolves to a Stash instance.

stash.pop()

Retrieve the next item from your stash in FIFO fashion.

stash.size

Get the number of items in the stash.


License

MIT