1.1.2 • Published 7 years ago

function-batch v1.1.2

Weekly downloads
14
License
MIT
Repository
github
Last release
7 years ago

function-batch

NPM version NPM downloads Build Status codecov Dependency Status

Creates a batched function that will batch up all calls to it, and then after a threshold call the original function with all the args combined.

How to Install

npm install function-batch

Usage

import functionBatch from 'function-batch';

const returnArr = (arr) => arr;
const returnArrBatched = functionBatch(returnArr);

const value = Promise.all([
  returnArrBatched([1]);
  returnArrBatched([2]);
  returnArrBatched([3]);
  returnArrBatched([4]);
])
.then(([a, b, c, d]) => {
// All resolve with the same value.
// a = [1, 2, 3, 4]
// b = [1, 2, 3, 4]
// c = [1, 2, 3, 4]
// d = [1, 2, 3, 4]
});

Currently function-batch only supports batching up arrays. Support for different kinds of args will be added if requested!

Api

function: functionBatch(func, wait, options): Promise<*>

paramtyperequired
funcFunctionyes
waitnumberyes
optionsOptionsno

object: Options

paramtyperequired
leadingbooleanno
trailingbooleanno
maxWaitnumberno
1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.0

7 years ago

0.1.5

7 years ago

0.1.4

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago