Gathering detailed insights and metrics for @stdlib/utils-async-until
Gathering detailed insights and metrics for @stdlib/utils-async-until
Gathering detailed insights and metrics for @stdlib/utils-async-until
Gathering detailed insights and metrics for @stdlib/utils-async-until
Invoke a function until a test condition is true.
npm install @stdlib/utils-async-until
Typescript
Module System
Min. Node Version
Node Version
NPM Version
70.8
Supply Chain
90.2
Quality
81.6
Maintenance
100
Vulnerability
88
License
JavaScript (100%)
Total Downloads
5,180
Last Day
3
Last Week
14
Last Month
97
Last Year
1,063
Apache-2.0 License
2 Stars
68 Commits
3 Watchers
5 Branches
13 Contributors
Updated on Feb 03, 2025
Minified
Minified + Gzipped
Latest Version
0.2.2
Package Id
@stdlib/utils-async-until@0.2.2
Unpacked Size
36.12 kB
Size
9.78 kB
File Count
11
NPM Version
8.19.4
Node Version
16.20.2
Published on
Jul 27, 2024
Cumulative downloads
Total Downloads
Last Day
-50%
3
Compared to previous day
Last Week
-26.3%
14
Compared to previous week
Last Month
14.1%
97
Compared to previous month
Last Year
-19.7%
1,063
Compared to previous year
We believe in a future in which the web is a preferred environment for numerical computation. To help realize this future, we've built stdlib. stdlib is a standard library, with an emphasis on numerical and scientific computation, written in JavaScript (and C) for execution in browsers and in Node.js.
The library is fully decomposable, being architected in such a way that you can swap out and mix and match APIs and functionality to cater to your exact preferences and use cases.
When you use stdlib, you can be absolutely certain that you are using the most thorough, rigorous, well-written, studied, documented, tested, measured, and high-quality code out there.
To join us in bringing numerical computing to the web, get started by checking us out on GitHub, and please consider financially supporting stdlib. We greatly appreciate your continued support!
Invoke a function until a test condition is true.
1npm install @stdlib/utils-async-until
1var untilAsync = require( '@stdlib/utils-async-until' );
Invokes a function
until a predicate
function returns true
.
1function predicate( i, clbk ) { 2 clbk( null, i >= 5 ); 3} 4 5function fcn( i, next ) { 6 setTimeout( onTimeout, 0 ); 7 function onTimeout() { 8 console.log( 'beep: %d', i ); 9 next(); 10 } 11} 12 13function done( error ) { 14 if ( error ) { 15 throw error; 16 } 17} 18 19untilAsync( predicate, fcn, done ); 20/* => 21 beep: 0 22 beep: 1 23 beep: 2 24 beep: 3 25 beep: 4 26*/
The predicate
function is provided two arguments:
i
: iteration number (starting from zero)clbk
: a callback indicating whether to invoke fcn
The clbk
function accepts two arguments:
error
: error objectbool
: test resultIf the test result is falsy, the function invokes fcn
; otherwise, the function invokes the done
callback.
The function to invoke is provided two arguments:
i
: iteration number (starting from zero)next
: a callback which must be invoked before proceeding to the next iterationThe first argument of both clbk
and next
is an error
argument. If either function is called with a truthy error
argument, the function suspends execution and immediately calls the done
callback for subsequent error
handling.
1function predicate( i, clbk ) { 2 clbk( null, i >= 5 ); 3} 4 5function fcn( i, next ) { 6 setTimeout( onTimeout, 0 ); 7 function onTimeout() { 8 next( new Error( 'beep' ) ); 9 } 10} 11 12function done( error ) { 13 console.error( error.message ); 14 // => beep 15} 16 17untilAsync( predicate, fcn, done );
The done
callback is invoked with an error
argument and any arguments passed to the final next
callback.
1function predicate( i, clbk ) { 2 clbk( null, i >= 5 ); 3} 4 5function fcn( i, next ) { 6 setTimeout( onTimeout, 0 ); 7 function onTimeout() { 8 next( null, i ); 9 } 10} 11 12function done( error, result ) { 13 if ( error ) { 14 throw error; 15 } 16 console.log( result ); 17 // => 4 18} 19 20untilAsync( predicate, fcn, done );
To set the function execution context for the invoked function, provide a thisArg
.
1function predicate( i, clbk ) { 2 clbk( null, i >= 5 ); 3} 4 5function fcn( i, next ) { 6 this.count += 1; 7 setTimeout( onTimeout, 0 ); 8 function onTimeout() { 9 next(); 10 } 11} 12 13var context = { 14 'count': 0 15}; 16 17untilAsync( predicate, fcn, done, context ); 18 19function done( error ) { 20 if ( error ) { 21 throw error; 22 } 23 console.log( context.count ); 24 // => 5 25}
done
callback in a function which either executes at the end of the current stack (e.g., nextTick
) or during a subsequent turn of the event loop (e.g., setImmediate
, setTimeout
).1var repeatString = require( '@stdlib/string-repeat' ); 2var untilAsync = require( '@stdlib/utils-async-until' ); 3 4function predicate( i, clbk ) { 5 setTimeout( onTimeout, 0 ); 6 function onTimeout() { 7 clbk( null, i >= 5 ); 8 } 9} 10 11function fcn( i, next ) { 12 setTimeout( onTimeout, 0 ); 13 function onTimeout() { 14 next( null, repeatString( 'beep', i+1 ) ); 15 } 16} 17 18function done( error, result ) { 19 if ( error ) { 20 throw error; 21 } 22 console.log( result ); 23} 24 25untilAsync( predicate, fcn, done );
@stdlib/utils-async/do-until
: invoke a function until a test condition is true.@stdlib/utils-async/do-while
: invoke a function while a test condition is true.@stdlib/utils-until
: invoke a function until a test condition is true.@stdlib/utils-async/while
: invoke a function while a test condition is true.This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.
See LICENSE.
Copyright © 2016-2024. The Stdlib Authors.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
security policy file detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
Reason
1 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
no SAST tool detected
Details
Reason
project is not fuzzed
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2025-04-28
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More