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.