Skip to content

Latest commit

 

History

History
43 lines (35 loc) · 2.63 KB

discard.md

File metadata and controls

43 lines (35 loc) · 2.63 KB

Async Agent

A javascript library of async functions

npm build coverage deps size vulnerabilities license


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.

Returns: Promise - The promise is resolved after every callback is resolved or one is rejected. If iterations complete without rejection, then the array is mutated and the Promise is resolved with an array of the discarded elements.

Param Type Default Description
array Array An array to iterate over.
callback function Parameters: element, index, and array.
Context: same as that provided to the main function.
Return: A truthy value to discard that element.
May return a Promise. Rejections are not caught and any work done up to that point will be lost.
[settings] object Optional settings object.
[settings.down] boolean false Decrement the index on each iteration from highest to lowest.
[settings.delay] number 0 Delay before calls in ms. Can be updated at any time to effect the delay before future calls.