pregen-stash

0.1.1 • Public • Published

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

Package Sidebar

Install

npm i pregen-stash

Weekly Downloads

2

Version

0.1.1

License

MIT

Unpacked Size

6.27 kB

Total Files

10

Last publish

Collaborators

  • chiefbiiko