@stdlib/utils-async-every-by 0.0.7 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CITATION.cff +30 -0
- package/LICENSE +0 -304
- package/NOTICE +1 -1
- package/README.md +101 -36
- package/dist/index.d.ts +3 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +7 -0
- package/docs/types/index.d.ts +14 -19
- package/lib/factory.js +4 -4
- package/lib/index.js +3 -3
- package/lib/limit.js +1 -1
- package/lib/{every_by.js → main.js} +0 -1
- package/lib/validate.js +4 -3
- package/package.json +19 -17
- package/docs/repl.txt +0 -209
- package/docs/types/test.ts +0 -152
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../lib/validate.js", "../lib/limit.js", "../lib/factory.js", "../lib/main.js", "../lib/index.js"],
|
|
4
|
+
"sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive;\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {*} [options.thisArg] - execution context\n* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time\n* @param {boolean} [options.series] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'thisArg': {},\n* 'series': false,\n* 'limit': 10\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'thisArg' ) ) {\n\t\topts.thisArg = options.thisArg;\n\t}\n\tif ( hasOwnProp( options, 'series' ) ) {\n\t\topts.series = options.series;\n\t\tif ( !isBoolean( opts.series ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'series', opts.series ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'limit' ) ) {\n\t\topts.limit = options.limit;\n\t\tif ( !isPositiveInteger( opts.limit ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a positive integer. Option: `%s`.', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar logger = require( 'debug' );\n\n\n// VARIABLES //\n\nvar debug = logger( 'every-by-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a predicate function once for each element in a collection, limiting the number of concurrently pending functions.\n*\n* @private\n* @param {Collection} collection - input collection\n* @param {Options} opts - function options\n* @param {*} [opts.thisArg] - execution context\n* @param {PositiveInteger} [opts.limit] - maximum number of pending function invocations\n* @param {Function} predicate - predicate function\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, opts, predicate, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar i;\n\n\tlen = collection.length;\n\tdebug( 'Collection length: %d', len );\n\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing a collection.' );\n\t\treturn done( null, true );\n\t}\n\tif ( len < opts.limit ) {\n\t\tlim = len;\n\t} else {\n\t\tlim = opts.limit;\n\t}\n\tdebug( 'Concurrency limit: %d', lim );\n\tdebug( 'Number of arguments: %d', predicate.length );\n\n\tmaxIndex = len - 1;\n\tcount = 0;\n\tidx = -1;\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all collection elements...\n\t\tif ( idx < maxIndex ) {\n\t\t\tnext(); // eslint-disable-line node/callback-return\n\t\t}\n\t}\n\n\t/**\n\t* Callback to invoke a provided function for the next element in a collection.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tidx += 1;\n\t\tdebug( 'Collection element %d: %s.', idx, JSON.stringify( collection[ idx ] ) );\n\t\tif ( predicate.length === 2 ) {\n\t\t\tpredicate.call( opts.thisArg, collection[ idx ], clbk );\n\t\t} else if ( predicate.length === 3 ) {\n\t\t\tpredicate.call( opts.thisArg, collection[ idx ], idx, clbk );\n\t\t} else {\n\t\t\tpredicate.call( opts.thisArg, collection[ idx ], idx, collection, clbk ); // eslint-disable-line max-len\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once a provided function finishes processing a collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @param {*} [result] - test result\n\t* @returns {void}\n\t*/\n\tfunction clbk( error, result ) {\n\t\tif ( flg ) {\n\t\t\t// Prevent further processing of collection elements:\n\t\t\treturn;\n\t\t}\n\t\tif ( error ) {\n\t\t\tflg = true;\n\t\t\tdebug( 'Encountered an error: %s', error.message );\n\t\t\treturn done( error );\n\t\t}\n\t\tcount += 1;\n\t\tdebug( 'Processed %d of %d collection elements.', count, len );\n\n\t\tdebug( 'Test result: %s', !!result );\n\t\tif ( !result && !flg ) {\n\t\t\tflg = true;\n\t\t\tdebug( 'Finished processing a collection.' );\n\t\t\treturn done( null, false );\n\t\t}\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing a collection.' );\n\t\t\treturn done( null, true );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = limit;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar PINF = require( '@stdlib/constants-float64-pinf' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\nvar limit = require( './limit.js' );\n\n\n// MAIN //\n\n/**\n* Returns a function for testing whether all elements in a collection pass a test implemented by a predicate function.\n*\n* ## Notes\n*\n* - If a predicate function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling.\n* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `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`).\n*\n* @param {Options} [options] - function options\n* @param {*} [options.thisArg] - execution context\n* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time\n* @param {boolean} [options.series=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection\n* @param {Function} predicate - predicate function to invoke for each element in a collection\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {TypeError} last argument must be a function\n* @returns {Function} function which invokes the predicate function once for each element in a collection\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n*\n* function predicate( file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, false );\n* }\n* next( null, true );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create an `everyByAsync` function which invokes the predicate function for each collection element sequentially:\n* var everyByAsync = factory( opts, predicate );\n*\n* // Create a collection over which to iterate:\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* // Define a callback which handles results:\n* function done( error, bool ) {\n* if ( error ) {\n* throw error;\n* }\n* if ( bool ) {\n* console.log( 'Successfully read all files.' );\n* } else {\n* console.log( 'Was unable to read all files.' );\n* }\n* }\n*\n* // Try to read each element in `files`:\n* everyByAsync( files, done );\n*/\nfunction factory( options, predicate ) {\n\tvar opts;\n\tvar err;\n\tvar f;\n\n\topts = {};\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t\tf = predicate;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn everyByAsync;\n\n\t/**\n\t* Invokes a predicate function for each element in a collection.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction everyByAsync( collection, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. First argument must be a collection. Value: `%s`.', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) );\n\t\t}\n\t\treturn limit( collection, opts, f, clbk );\n\n\t\t/**\n\t\t* Callback invoked upon completion.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {boolean} bool - test result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, bool ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error, false );\n\t\t\t}\n\t\t\tdone( null, bool );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\n/**\n* Tests whether all elements in a collection pass a test implemented by a predicate function.\n*\n* ## Notes\n*\n* - If a predicate function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling.\n* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `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`).\n*\n* @param {Collection} collection - input collection\n* @param {Options} [options] - function options\n* @param {*} [options.thisArg] - execution context\n* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time\n* @param {boolean} [options.series=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection\n* @param {Function} predicate - predicate function to invoke for each element in a collection\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be a collection\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {TypeError} second-to-last argument must be a function\n* @throws {TypeError} last argument must be a function\n* @returns {void}\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n*\n* function done( error, bool ) {\n* if ( error ) {\n* throw error;\n* }\n* if ( bool ) {\n* console.log( 'Successfully read all files.' );\n* } else {\n* console.log( 'Was unable to read all files.' );\n* }\n* }\n*\n* function predicate( file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, false );\n* }\n* next( null, true );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* everyByAsync( files, predicate, done );\n*/\nfunction everyByAsync( collection, options, predicate, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( collection, predicate );\n\t}\n\tfactory( options, predicate )( collection, done );\n}\n\n\n// EXPORTS //\n\nmodule.exports = everyByAsync;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Test whether all elements in a collection pass a test implemented by a predicate function.\n*\n* @module @stdlib/utils-async-every-by\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n* var everyByAsync = require( '@stdlib/utils-async-every-by' );\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, bool ) {\n* if ( error ) {\n* throw error;\n* }\n* if ( bool ) {\n* console.log( 'Successfully read all files.' );\n* } else {\n* console.log( 'Was unable to read all files.' );\n* }\n* }\n*\n* function predicate( file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, false );\n* }\n* next( null, true );\n* }\n* }\n*\n* everyByAsync( files, predicate, done );\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
|
+
"names": ["require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isBoolean", "isPositiveInteger", "format", "validate", "opts", "options", "require_limit", "__commonJSMin", "exports", "module", "logger", "debug", "limit", "collection", "opts", "predicate", "done", "maxIndex", "count", "flg", "lim", "len", "idx", "i", "next", "clbk", "error", "result", "require_factory", "__commonJSMin", "exports", "module", "isFunction", "isCollection", "PINF", "format", "validate", "limit", "factory", "options", "predicate", "opts", "err", "f", "everyByAsync", "collection", "done", "clbk", "error", "bool", "require_main", "__commonJSMin", "exports", "module", "factory", "everyByAsync", "collection", "options", "predicate", "done", "setReadOnly", "main", "factory"]
|
|
7
|
+
}
|
package/docs/types/index.d.ts
CHANGED
|
@@ -16,16 +16,16 @@
|
|
|
16
16
|
* limitations under the License.
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
|
-
// TypeScript Version:
|
|
19
|
+
// TypeScript Version: 4.1
|
|
20
20
|
|
|
21
21
|
/// <reference types="@stdlib/types"/>
|
|
22
22
|
|
|
23
|
-
import { Collection } from '@stdlib/types/
|
|
23
|
+
import { Collection } from '@stdlib/types/array';
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
26
|
* Interface defining function options.
|
|
27
27
|
*/
|
|
28
|
-
interface Options {
|
|
28
|
+
interface Options<T, V> {
|
|
29
29
|
/**
|
|
30
30
|
* The maximum number of pending invocations at any one time.
|
|
31
31
|
*/
|
|
@@ -39,7 +39,7 @@ interface Options {
|
|
|
39
39
|
/**
|
|
40
40
|
* Execution context.
|
|
41
41
|
*/
|
|
42
|
-
thisArg?:
|
|
42
|
+
thisArg?: ThisParameterType<Predicate<T, V>>;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
/**
|
|
@@ -76,7 +76,7 @@ type Callback = Nullary | Unary | Binary;
|
|
|
76
76
|
* @param value - collection value
|
|
77
77
|
* @param next - callback which should be called once the predicate function has finished processing a collection value
|
|
78
78
|
*/
|
|
79
|
-
type BinaryPredicate = ( value:
|
|
79
|
+
type BinaryPredicate<T, V> = ( this: V, value: T, next: Callback ) => void;
|
|
80
80
|
|
|
81
81
|
/**
|
|
82
82
|
* Checks whether an element in a collection passes a test.
|
|
@@ -85,7 +85,7 @@ type BinaryPredicate = ( value: any, next: Callback ) => void;
|
|
|
85
85
|
* @param index - collection index
|
|
86
86
|
* @param next - callback which should be called once the `predicate` function has finished processing a collection `value`
|
|
87
87
|
*/
|
|
88
|
-
type
|
|
88
|
+
type TernaryPredicate<T, V> = ( this: V, value: T, index: number, next: Callback ) => void;
|
|
89
89
|
|
|
90
90
|
/**
|
|
91
91
|
* Checks whether an element in a collection passes a test.
|
|
@@ -95,7 +95,7 @@ type TertiaryPredicate = ( value: any, index: number, next: Callback ) => void;
|
|
|
95
95
|
* @param collection - input collection
|
|
96
96
|
* @param next - callback which should be called once the `predicate` function has finished processing a collection `value`
|
|
97
97
|
*/
|
|
98
|
-
type QuaternaryPredicate = ( value:
|
|
98
|
+
type QuaternaryPredicate<T, V> = ( this: V, value: T, index: number, collection: Collection<T>, next: Callback ) => void;
|
|
99
99
|
|
|
100
100
|
/**
|
|
101
101
|
* Checks whether an element in a collection passes a test.
|
|
@@ -105,15 +105,15 @@ type QuaternaryPredicate = ( value: any, index: number, collection: Collection,
|
|
|
105
105
|
* @param collection - input collection
|
|
106
106
|
* @param next - callback which should be called once the `predicate` function has finished processing a collection `value`
|
|
107
107
|
*/
|
|
108
|
-
type Predicate = BinaryPredicate |
|
|
108
|
+
type Predicate<T, V> = BinaryPredicate<T, V> | TernaryPredicate<T, V> | QuaternaryPredicate<T, V>;
|
|
109
109
|
|
|
110
110
|
/**
|
|
111
|
-
* Tests whether all elements in a collection
|
|
111
|
+
* Tests whether all elements in a collection passes a test implemented by a predicate function.
|
|
112
112
|
*
|
|
113
113
|
* @param collection - input collection
|
|
114
114
|
* @param done - function to invoke upon completion
|
|
115
115
|
*/
|
|
116
|
-
type FactoryFunction = ( collection: Collection
|
|
116
|
+
type FactoryFunction<T> = ( collection: Collection<T>, done: Callback ) => void;
|
|
117
117
|
|
|
118
118
|
/**
|
|
119
119
|
* Interface for `everyByAsync`.
|
|
@@ -127,7 +127,6 @@ interface EveryByAsync {
|
|
|
127
127
|
* - If a predicate function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling.
|
|
128
128
|
* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `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`).
|
|
129
129
|
*
|
|
130
|
-
*
|
|
131
130
|
* @param collection - input collection
|
|
132
131
|
* @param options - function options
|
|
133
132
|
* @param options.thisArg - execution context
|
|
@@ -172,7 +171,7 @@ interface EveryByAsync {
|
|
|
172
171
|
*
|
|
173
172
|
* everyByAsync( files, predicate, done );
|
|
174
173
|
*/
|
|
175
|
-
( collection: Collection
|
|
174
|
+
<T = unknown, V = unknown>( collection: Collection<T>, options: Options<T, V>, predicate: Predicate<T, V>, done: Callback ): void;
|
|
176
175
|
|
|
177
176
|
/**
|
|
178
177
|
* Tests whether all elements in a collection pass a test implemented by a predicate function.
|
|
@@ -182,7 +181,6 @@ interface EveryByAsync {
|
|
|
182
181
|
* - If a predicate function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling.
|
|
183
182
|
* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `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`).
|
|
184
183
|
*
|
|
185
|
-
*
|
|
186
184
|
* @param collection - input collection
|
|
187
185
|
* @param predicate - predicate function to invoke for each element in a collection
|
|
188
186
|
* @param done - function to invoke upon completion
|
|
@@ -223,7 +221,7 @@ interface EveryByAsync {
|
|
|
223
221
|
*
|
|
224
222
|
* everyByAsync( files, predicate, done );
|
|
225
223
|
*/
|
|
226
|
-
( collection: Collection
|
|
224
|
+
<T = unknown, V = unknown>( collection: Collection<T>, predicate: Predicate<T, V>, done: Callback ): void; // tslint:disable-line:no-unnecessary-generics
|
|
227
225
|
|
|
228
226
|
/**
|
|
229
227
|
* Returns a function for testing whether all elements in a collection pass a test implemented by a predicate function.
|
|
@@ -233,7 +231,6 @@ interface EveryByAsync {
|
|
|
233
231
|
* - If a predicate function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling.
|
|
234
232
|
* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `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`).
|
|
235
233
|
*
|
|
236
|
-
*
|
|
237
234
|
* @param options - function options
|
|
238
235
|
* @param options.thisArg - execution context
|
|
239
236
|
* @param options.limit - maximum number of pending invocations at any one time
|
|
@@ -287,7 +284,7 @@ interface EveryByAsync {
|
|
|
287
284
|
* // Try to read each element in `files`:
|
|
288
285
|
* everyByAsync( files, done );
|
|
289
286
|
*/
|
|
290
|
-
factory( options: Options, predicate: Predicate ): FactoryFunction
|
|
287
|
+
factory<T = unknown, V = unknown>( options: Options<T, V>, predicate: Predicate<T, V> ): FactoryFunction<T>;
|
|
291
288
|
|
|
292
289
|
/**
|
|
293
290
|
* Returns a function for testing whether all elements in a collection pass a test implemented by a predicate function.
|
|
@@ -297,7 +294,6 @@ interface EveryByAsync {
|
|
|
297
294
|
* - If a predicate function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling.
|
|
298
295
|
* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `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`).
|
|
299
296
|
*
|
|
300
|
-
*
|
|
301
297
|
* @param predicate - predicate function to invoke for each element in a collection
|
|
302
298
|
* @throws must provide valid options
|
|
303
299
|
* @returns function which invokes the predicate function once for each element in a collection
|
|
@@ -347,7 +343,7 @@ interface EveryByAsync {
|
|
|
347
343
|
* // Try to read each element in `files`:
|
|
348
344
|
* everyByAsync( files, done );
|
|
349
345
|
*/
|
|
350
|
-
factory( predicate: Predicate ): FactoryFunction
|
|
346
|
+
factory<T = unknown, V = unknown>( predicate: Predicate<T, V> ): FactoryFunction<T>; // tslint:disable-line:no-unnecessary-generics
|
|
351
347
|
}
|
|
352
348
|
|
|
353
349
|
/**
|
|
@@ -358,7 +354,6 @@ interface EveryByAsync {
|
|
|
358
354
|
* - If a predicate function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling.
|
|
359
355
|
* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `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`).
|
|
360
356
|
*
|
|
361
|
-
*
|
|
362
357
|
* @param collection - input collection
|
|
363
358
|
* @param options - function options
|
|
364
359
|
* @param options.thisArg - execution context
|
package/lib/factory.js
CHANGED
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
var isFunction = require( '@stdlib/assert-is-function' );
|
|
24
24
|
var isCollection = require( '@stdlib/assert-is-collection' );
|
|
25
25
|
var PINF = require( '@stdlib/constants-float64-pinf' );
|
|
26
|
+
var format = require( '@stdlib/string-format' );
|
|
26
27
|
var validate = require( './validate.js' );
|
|
27
28
|
var limit = require( './limit.js' );
|
|
28
29
|
|
|
@@ -37,7 +38,6 @@ var limit = require( './limit.js' );
|
|
|
37
38
|
* - If a predicate function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling.
|
|
38
39
|
* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `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`).
|
|
39
40
|
*
|
|
40
|
-
*
|
|
41
41
|
* @param {Options} [options] - function options
|
|
42
42
|
* @param {*} [options.thisArg] - execution context
|
|
43
43
|
* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time
|
|
@@ -109,7 +109,7 @@ function factory( options, predicate ) {
|
|
|
109
109
|
f = options;
|
|
110
110
|
}
|
|
111
111
|
if ( !isFunction( f ) ) {
|
|
112
|
-
throw new TypeError( 'invalid argument. Last argument must be a function. Value:
|
|
112
|
+
throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) );
|
|
113
113
|
}
|
|
114
114
|
if ( opts.series ) {
|
|
115
115
|
opts.limit = 1;
|
|
@@ -130,10 +130,10 @@ function factory( options, predicate ) {
|
|
|
130
130
|
*/
|
|
131
131
|
function everyByAsync( collection, done ) {
|
|
132
132
|
if ( !isCollection( collection ) ) {
|
|
133
|
-
throw new TypeError( 'invalid argument. First argument must be a collection. Value:
|
|
133
|
+
throw new TypeError( format( 'invalid argument. First argument must be a collection. Value: `%s`.', collection ) );
|
|
134
134
|
}
|
|
135
135
|
if ( !isFunction( done ) ) {
|
|
136
|
-
throw new TypeError( 'invalid argument. Last argument must be a function. Value:
|
|
136
|
+
throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) );
|
|
137
137
|
}
|
|
138
138
|
return limit( collection, opts, f, clbk );
|
|
139
139
|
|
package/lib/index.js
CHANGED
|
@@ -63,15 +63,15 @@
|
|
|
63
63
|
// MODULES //
|
|
64
64
|
|
|
65
65
|
var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );
|
|
66
|
-
var
|
|
66
|
+
var main = require( './main.js' );
|
|
67
67
|
var factory = require( './factory.js' );
|
|
68
68
|
|
|
69
69
|
|
|
70
70
|
// MAIN //
|
|
71
71
|
|
|
72
|
-
setReadOnly(
|
|
72
|
+
setReadOnly( main, 'factory', factory );
|
|
73
73
|
|
|
74
74
|
|
|
75
75
|
// EXPORTS //
|
|
76
76
|
|
|
77
|
-
module.exports =
|
|
77
|
+
module.exports = main;
|
package/lib/limit.js
CHANGED
|
@@ -72,7 +72,7 @@ function limit( collection, opts, predicate, done ) {
|
|
|
72
72
|
for ( i = 0; i < lim; i++ ) {
|
|
73
73
|
// This guard is necessary to protect against synchronous functions which exhaust all collection elements...
|
|
74
74
|
if ( idx < maxIndex ) {
|
|
75
|
-
next(); // eslint-disable-line callback-return
|
|
75
|
+
next(); // eslint-disable-line node/callback-return
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
|
|
@@ -33,7 +33,6 @@ var factory = require( './factory.js' );
|
|
|
33
33
|
* - If a predicate function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling.
|
|
34
34
|
* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `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`).
|
|
35
35
|
*
|
|
36
|
-
*
|
|
37
36
|
* @param {Collection} collection - input collection
|
|
38
37
|
* @param {Options} [options] - function options
|
|
39
38
|
* @param {*} [options.thisArg] - execution context
|
package/lib/validate.js
CHANGED
|
@@ -24,6 +24,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' );
|
|
|
24
24
|
var hasOwnProp = require( '@stdlib/assert-has-own-property' );
|
|
25
25
|
var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;
|
|
26
26
|
var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive;
|
|
27
|
+
var format = require( '@stdlib/string-format' );
|
|
27
28
|
|
|
28
29
|
|
|
29
30
|
// MAIN //
|
|
@@ -53,7 +54,7 @@ var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimit
|
|
|
53
54
|
*/
|
|
54
55
|
function validate( opts, options ) {
|
|
55
56
|
if ( !isObject( options ) ) {
|
|
56
|
-
return new TypeError( 'invalid argument. Options must be an object. Value:
|
|
57
|
+
return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
|
|
57
58
|
}
|
|
58
59
|
if ( hasOwnProp( options, 'thisArg' ) ) {
|
|
59
60
|
opts.thisArg = options.thisArg;
|
|
@@ -61,13 +62,13 @@ function validate( opts, options ) {
|
|
|
61
62
|
if ( hasOwnProp( options, 'series' ) ) {
|
|
62
63
|
opts.series = options.series;
|
|
63
64
|
if ( !isBoolean( opts.series ) ) {
|
|
64
|
-
return new TypeError( 'invalid option. `
|
|
65
|
+
return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'series', opts.series ) );
|
|
65
66
|
}
|
|
66
67
|
}
|
|
67
68
|
if ( hasOwnProp( options, 'limit' ) ) {
|
|
68
69
|
opts.limit = options.limit;
|
|
69
70
|
if ( !isPositiveInteger( opts.limit ) ) {
|
|
70
|
-
return new TypeError( 'invalid option. `
|
|
71
|
+
return new TypeError( format( 'invalid option. `%s` option must be a positive integer. Option: `%s`.', 'limit', opts.limit ) );
|
|
71
72
|
}
|
|
72
73
|
}
|
|
73
74
|
return null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stdlib/utils-async-every-by",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "Test whether all elements in a collection pass a test implemented by a predicate function.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": {
|
|
@@ -37,24 +37,26 @@
|
|
|
37
37
|
"url": "https://github.com/stdlib-js/stdlib/issues"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@stdlib/assert-has-own-property": "^0.0
|
|
41
|
-
"@stdlib/assert-is-boolean": "^0.0
|
|
42
|
-
"@stdlib/assert-is-collection": "^0.0
|
|
43
|
-
"@stdlib/assert-is-function": "^0.0
|
|
44
|
-
"@stdlib/assert-is-plain-object": "^0.0
|
|
45
|
-
"@stdlib/assert-is-positive-integer": "^0.0
|
|
46
|
-
"@stdlib/constants-float64-pinf": "^0.0
|
|
47
|
-
"@stdlib/
|
|
48
|
-
"@stdlib/
|
|
49
|
-
"
|
|
40
|
+
"@stdlib/assert-has-own-property": "^0.1.0",
|
|
41
|
+
"@stdlib/assert-is-boolean": "^0.1.0",
|
|
42
|
+
"@stdlib/assert-is-collection": "^0.1.0",
|
|
43
|
+
"@stdlib/assert-is-function": "^0.1.0",
|
|
44
|
+
"@stdlib/assert-is-plain-object": "^0.1.0",
|
|
45
|
+
"@stdlib/assert-is-positive-integer": "^0.1.0",
|
|
46
|
+
"@stdlib/constants-float64-pinf": "^0.1.0",
|
|
47
|
+
"@stdlib/string-format": "^0.1.0",
|
|
48
|
+
"@stdlib/types": "^0.1.0",
|
|
49
|
+
"@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.0",
|
|
50
|
+
"debug": "^2.6.9",
|
|
51
|
+
"@stdlib/error-tools-fmtprodmsg": "^0.1.0"
|
|
50
52
|
},
|
|
51
53
|
"devDependencies": {
|
|
52
|
-
"@stdlib/bench": "^0.0
|
|
53
|
-
"@stdlib/fs-read-file": "^0.0
|
|
54
|
-
"@stdlib/utils-noop": "^0.0
|
|
54
|
+
"@stdlib/bench": "^0.1.0",
|
|
55
|
+
"@stdlib/fs-read-file": "^0.1.0",
|
|
56
|
+
"@stdlib/utils-noop": "^0.1.0",
|
|
55
57
|
"tape": "git+https://github.com/kgryte/tape.git#fix/globby",
|
|
56
58
|
"istanbul": "^0.4.1",
|
|
57
|
-
"tap-
|
|
59
|
+
"tap-min": "git+https://github.com/Planeshifter/tap-min.git"
|
|
58
60
|
},
|
|
59
61
|
"engines": {
|
|
60
62
|
"node": ">=0.10.0",
|
|
@@ -92,7 +94,7 @@
|
|
|
92
94
|
"validate"
|
|
93
95
|
],
|
|
94
96
|
"funding": {
|
|
95
|
-
"type": "
|
|
96
|
-
"url": "https://
|
|
97
|
+
"type": "opencollective",
|
|
98
|
+
"url": "https://opencollective.com/stdlib"
|
|
97
99
|
}
|
|
98
100
|
}
|
package/docs/repl.txt
DELETED
|
@@ -1,209 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
{{alias}}( collection, [options,] predicate, done )
|
|
3
|
-
Tests whether all elements in a collection pass a test implemented by a
|
|
4
|
-
predicate function.
|
|
5
|
-
|
|
6
|
-
When invoked, the predicate function is provided a maximum of four
|
|
7
|
-
arguments:
|
|
8
|
-
|
|
9
|
-
- `value`: collection value
|
|
10
|
-
- `index`: collection index
|
|
11
|
-
- `collection`: the input collection
|
|
12
|
-
- `next`: a callback to be invoked after processing a collection `value`
|
|
13
|
-
|
|
14
|
-
The actual number of provided arguments depends on function length. If the
|
|
15
|
-
predicate function accepts two arguments, the predicate function is
|
|
16
|
-
provided:
|
|
17
|
-
|
|
18
|
-
- `value`
|
|
19
|
-
- `next`
|
|
20
|
-
|
|
21
|
-
If the predicate function accepts three arguments, the predicate function is
|
|
22
|
-
provided:
|
|
23
|
-
|
|
24
|
-
- `value`
|
|
25
|
-
- `index`
|
|
26
|
-
- `next`
|
|
27
|
-
|
|
28
|
-
For every other predicate function signature, the predicate function is
|
|
29
|
-
provided all four arguments.
|
|
30
|
-
|
|
31
|
-
The `next` callback takes two arguments:
|
|
32
|
-
|
|
33
|
-
- `error`: error argument
|
|
34
|
-
- `result`: test result
|
|
35
|
-
|
|
36
|
-
If a provided function calls the `next` callback with a truthy `error`
|
|
37
|
-
argument, the function suspends execution and immediately calls the `done`
|
|
38
|
-
callback for subsequent `error` handling.
|
|
39
|
-
|
|
40
|
-
The function immediately returns upon encountering a non-truthy `result`
|
|
41
|
-
value and calls the `done` callback with `null` as the first argument and
|
|
42
|
-
`false` as the second argument.
|
|
43
|
-
|
|
44
|
-
If all elements succeed, the function calls the `done` callback with `null`
|
|
45
|
-
as the first argument and `true` as the second argument.
|
|
46
|
-
|
|
47
|
-
Execution is *not* guaranteed to be asynchronous. To guarantee asynchrony,
|
|
48
|
-
wrap the `done` callback in a function which either executes at the end of
|
|
49
|
-
the current stack (e.g., `nextTick`) or during a subsequent turn of the
|
|
50
|
-
event loop (e.g., `setImmediate`, `setTimeout`).
|
|
51
|
-
|
|
52
|
-
The function does not support dynamic collection resizing.
|
|
53
|
-
|
|
54
|
-
The function does not skip `undefined` elements.
|
|
55
|
-
|
|
56
|
-
Parameters
|
|
57
|
-
----------
|
|
58
|
-
collection: Array|TypedArray|Object
|
|
59
|
-
Input collection over which to iterate. If provided an object, the
|
|
60
|
-
object must be array-like (excluding strings and functions).
|
|
61
|
-
|
|
62
|
-
options: Object (optional)
|
|
63
|
-
Function options.
|
|
64
|
-
|
|
65
|
-
options.limit: integer (optional)
|
|
66
|
-
Maximum number of pending invocations. Default: Infinity.
|
|
67
|
-
|
|
68
|
-
options.series: boolean (optional)
|
|
69
|
-
Boolean indicating whether to process each collection element
|
|
70
|
-
sequentially. Default: false.
|
|
71
|
-
|
|
72
|
-
options.thisArg: any (optional)
|
|
73
|
-
Execution context.
|
|
74
|
-
|
|
75
|
-
predicate: Function
|
|
76
|
-
The test function to invoke for each element in a collection.
|
|
77
|
-
|
|
78
|
-
done: Function
|
|
79
|
-
A callback invoked either upon processing all collection elements or
|
|
80
|
-
upon encountering an error.
|
|
81
|
-
|
|
82
|
-
Examples
|
|
83
|
-
--------
|
|
84
|
-
// Basic usage:
|
|
85
|
-
> function predicate( value, next ) {
|
|
86
|
-
... setTimeout( onTimeout, value );
|
|
87
|
-
... function onTimeout() {
|
|
88
|
-
... console.log( value );
|
|
89
|
-
... next( null, true );
|
|
90
|
-
... }
|
|
91
|
-
... };
|
|
92
|
-
> function done( error, bool ) {
|
|
93
|
-
... if ( error ) {
|
|
94
|
-
... throw error;
|
|
95
|
-
... }
|
|
96
|
-
... console.log( bool );
|
|
97
|
-
... };
|
|
98
|
-
> var arr = [ 3000, 2500, 1000 ];
|
|
99
|
-
> {{alias}}( arr, predicate, done )
|
|
100
|
-
1000
|
|
101
|
-
2500
|
|
102
|
-
3000
|
|
103
|
-
true
|
|
104
|
-
|
|
105
|
-
// Limit number of concurrent invocations:
|
|
106
|
-
> function predicate( value, next ) {
|
|
107
|
-
... setTimeout( onTimeout, value );
|
|
108
|
-
... function onTimeout() {
|
|
109
|
-
... console.log( value );
|
|
110
|
-
... next( null, true );
|
|
111
|
-
... }
|
|
112
|
-
... };
|
|
113
|
-
> function done( error, bool ) {
|
|
114
|
-
... if ( error ) {
|
|
115
|
-
... throw error;
|
|
116
|
-
... }
|
|
117
|
-
... console.log( bool );
|
|
118
|
-
... };
|
|
119
|
-
> var opts = { 'limit': 2 };
|
|
120
|
-
> var arr = [ 3000, 2500, 1000 ];
|
|
121
|
-
> {{alias}}( arr, opts, predicate, done )
|
|
122
|
-
2500
|
|
123
|
-
3000
|
|
124
|
-
1000
|
|
125
|
-
true
|
|
126
|
-
|
|
127
|
-
// Process sequentially:
|
|
128
|
-
> function predicate( value, next ) {
|
|
129
|
-
... setTimeout( onTimeout, value );
|
|
130
|
-
... function onTimeout() {
|
|
131
|
-
... console.log( value );
|
|
132
|
-
... next( null, true );
|
|
133
|
-
... }
|
|
134
|
-
... };
|
|
135
|
-
> function done( error, bool ) {
|
|
136
|
-
... if ( error ) {
|
|
137
|
-
... throw error;
|
|
138
|
-
... }
|
|
139
|
-
... console.log( bool );
|
|
140
|
-
... };
|
|
141
|
-
> var opts = { 'series': true };
|
|
142
|
-
> var arr = [ 3000, 2500, 1000 ];
|
|
143
|
-
> {{alias}}( arr, opts, predicate, done )
|
|
144
|
-
3000
|
|
145
|
-
2500
|
|
146
|
-
1000
|
|
147
|
-
true
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
{{alias}}.factory( [options,] predicate )
|
|
151
|
-
Returns a function which tests whether all elements in a collection pass a
|
|
152
|
-
test implemented by a predicate function.
|
|
153
|
-
|
|
154
|
-
Parameters
|
|
155
|
-
----------
|
|
156
|
-
options: Object (optional)
|
|
157
|
-
Function options.
|
|
158
|
-
|
|
159
|
-
options.limit: integer (optional)
|
|
160
|
-
Maximum number of pending invocations. Default: Infinity.
|
|
161
|
-
|
|
162
|
-
options.series: boolean (optional)
|
|
163
|
-
Boolean indicating whether to process each collection element
|
|
164
|
-
sequentially. Default: false.
|
|
165
|
-
|
|
166
|
-
options.thisArg: any (optional)
|
|
167
|
-
Execution context.
|
|
168
|
-
|
|
169
|
-
predicate: Function
|
|
170
|
-
The test function to invoke for each element in a collection.
|
|
171
|
-
|
|
172
|
-
Returns
|
|
173
|
-
-------
|
|
174
|
-
out: Function
|
|
175
|
-
A function which tests each element in a collection.
|
|
176
|
-
|
|
177
|
-
Examples
|
|
178
|
-
--------
|
|
179
|
-
> function predicate( value, next ) {
|
|
180
|
-
... setTimeout( onTimeout, value );
|
|
181
|
-
... function onTimeout() {
|
|
182
|
-
... console.log( value );
|
|
183
|
-
... next( null, true );
|
|
184
|
-
... }
|
|
185
|
-
... };
|
|
186
|
-
> var opts = { 'series': true };
|
|
187
|
-
> var f = {{alias}}.factory( opts, predicate );
|
|
188
|
-
> function done( error, bool ) {
|
|
189
|
-
... if ( error ) {
|
|
190
|
-
... throw error;
|
|
191
|
-
... }
|
|
192
|
-
... console.log( bool );
|
|
193
|
-
... };
|
|
194
|
-
> var arr = [ 3000, 2500, 1000 ];
|
|
195
|
-
> f( arr, done )
|
|
196
|
-
3000
|
|
197
|
-
2500
|
|
198
|
-
1000
|
|
199
|
-
true
|
|
200
|
-
> arr = [ 2000, 1500, 1000 ];
|
|
201
|
-
> f( arr, done )
|
|
202
|
-
2000
|
|
203
|
-
1500
|
|
204
|
-
1000
|
|
205
|
-
true
|
|
206
|
-
|
|
207
|
-
See Also
|
|
208
|
-
--------
|
|
209
|
-
|