0.1.0 • Published 6 years ago

accumul v0.1.0

Weekly downloads
6
License
ISC
Repository
github
Last release
6 years ago

Example

$ npm install accumul --save

or using yarn

$ yarn add accumul
const { accumul } = require('accumul')
// ES2015 modules
import { accumul } from 'accumul'

const callingFunction = x => x * x

const releaseFunction = args => {
  console.log(args)
}

const buffered = accumul(callingFunction, 2000, releaseFunction)

buffered.fire(1)
buffered.fire(2)
buffered.fire(3)
buffered.fire(4)

// after ~2 seconds you will see in a console
// [1, 4, 9, 16]

// or you can release buffered values beforehand

const buffered = accumul(callingFunction, 2000, releaseFunction)

buffered.fire(1)
buffered.fire(2)
buffered.fire(3)

buffered.release()
// [1, 4, 9]

buffered.fire(4)
// after ~2 seconds you will see in a console
// [16]