README
Async Agent
A javascript library of async functions
Installation
npm install async-agent
Requires Babel 7.2+
Functions
- clear(id)
Clears a defer or delay callback.
- debounce(callback, [duration], [options]) ⇒
function
Returns a new debounced function that waits to call the callback until
duration
ms have passed since the last time it was called.- defer(callback) ⇒
number
Defers the calling of a callback until the current stack is complete.
- delay(callback, [duration]) ⇒
number
Delays the calling of a callback for a given amount of time.
- throttle(callback, [duration], [options]) ⇒
function
Returns a new throttled function that waits to call the callback until
duration
ms have passed. Any calls to it during that time will do nothing.- wait([duration]) ⇒
Promise
Delays the resolving of a new Promise for a given amount of time. Provides the same functionality as defer and delay, but with promises. Also serves as a wrapper for a Promise if a callback is provided in place of duration.
- rejectAfterBy(duration, callback) ⇒
function
Returns a function that returns a Promise that rejects with the results of a callback after a delay.
- rejectAfterWith([duration], [args]) ⇒
function
Returns a function that returns a Promise that rejects with provided args after a delay.
- rejectBy([callback]) ⇒
function
Returns a function that returns a Promise that rejects with the results of a callback.
- resolveWith([...args]) ⇒
function
Returns a function that returns a Promise that rejects with provided args.
- resolveAfterBy(duration, callback) ⇒
function
Returns a function that returns a Promise that resolves with the results of a callback after a delay.
- resolveAfterWith([duration], [arg]) ⇒
function
Returns a function that returns a Promise that resolves with provided args after a delay.
- resolveBy([callback]) ⇒
function
Returns a function that returns a Promise that resolves with the results of a callback.
- resolveWith([arg]) ⇒
function
Returns a function that returns a Promise that resolves with provided args.
- waitBy(callback) ⇒
function
Returns a function that returns a Promise that calls a callback.
- discard(array, callback, [settings]) ⇒
Promise
Discard elements from an array, in place, that pass an async test. The array is only mutated if and when all iterations are completed successfully.
- each(array, callback, [settings]) ⇒
Promise
Execute an async callback for each element in an array.
- every(array, callback, [settings]) ⇒
Promise
Determine whether every element in an array passes an async test.
- filter(array, callback, [settings]) ⇒
Promise
Create a new array with all the elements of an array that pass an async test.
- find(array, callback, [settings]) ⇒
Promise
Gets the first element in an array that passes an async test, or undefined if no element passes the test.
- findIndex(array, callback, [settings]) ⇒
Promise
Gets the index of the first element in an array that passes an async test, or -1 if no element passes the test.
- includes(array, value, [settings]) ⇒
Promise
Determines if an element is in an array. Uses SameValue comparison performed async.
- indexOf(array, value, [settings]) ⇒
Promise
Gets the index of an element in an array, or -1 if the element is not found in the array. Uses SameValue comparison performed async.
- map(array, callback, [settings]) ⇒
Promise
Create a new array populated with the results of calling an async callback on every element in an array.
- reduce(array, callback, initialValue, [settings]) ⇒
Promise
Calls an async callback on each element of an array, reducing the array to a single output value.
- some(array, callback, [settings]) ⇒
Promise
Determine whether at least one element in an array passes an async test.
- fill(length, [callback], [settings]) ⇒
Promise
Returns an array of specified length filled with either the index value or the value returned from an async callback.
- forRange(first, last, callback, [settings]) ⇒
Promise
Calls an async callback for each integer within a range.
- repeat(times, callback, [settings]) ⇒
Promise
Calls an async callback a specified number of times.
- until(callback, [settings]) ⇒
Promise
Calls an async callback until true is returned.