pregen-stash
v0.1.1
Published
stash that serves pregenerated values
Downloads
7
Maintainers
Readme
pregen-stash
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.