Skip to content

📦 Higher order function that will batch all calls to the wrapped function over a time period, and then call the wrapped function once with all args.

License

Notifications You must be signed in to change notification settings

itsdouges/function-batch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NPM version NPM downloads Build Status codecov Dependency Status

Higher order function that will batch all calls to the wrapped function over a debounce, and then call the wrapped function once.

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<*>

param type required
func Function yes
wait number yes
options Options no

object: Options

param type required
leading boolean no
trailing boolean no
maxWait number no

About

📦 Higher order function that will batch all calls to the wrapped function over a time period, and then call the wrapped function once with all args.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published