@stdlib/utils-async-parallel 0.1.0 → 0.1.1
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/NOTICE +1 -1
- package/README.md +5 -5
- package/dist/index.js.map +2 -2
- package/docs/types/index.d.ts +4 -8
- package/lib/limit.js +1 -1
- package/lib/main.js +0 -2
- package/package.json +10 -10
package/NOTICE
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Copyright (c) 2016-
|
|
1
|
+
Copyright (c) 2016-2026 The Stdlib Authors.
|
package/README.md
CHANGED
|
@@ -306,7 +306,7 @@ See [LICENSE][stdlib-license].
|
|
|
306
306
|
|
|
307
307
|
## Copyright
|
|
308
308
|
|
|
309
|
-
Copyright © 2016-
|
|
309
|
+
Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors].
|
|
310
310
|
|
|
311
311
|
</section>
|
|
312
312
|
|
|
@@ -319,8 +319,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
319
319
|
[npm-image]: http://img.shields.io/npm/v/@stdlib/utils-async-parallel.svg
|
|
320
320
|
[npm-url]: https://npmjs.org/package/@stdlib/utils-async-parallel
|
|
321
321
|
|
|
322
|
-
[test-image]: https://github.com/stdlib-js/utils-async-parallel/actions/workflows/test.yml/badge.svg?branch=v0.1.
|
|
323
|
-
[test-url]: https://github.com/stdlib-js/utils-async-parallel/actions/workflows/test.yml?query=branch:v0.1.
|
|
322
|
+
[test-image]: https://github.com/stdlib-js/utils-async-parallel/actions/workflows/test.yml/badge.svg?branch=v0.1.1
|
|
323
|
+
[test-url]: https://github.com/stdlib-js/utils-async-parallel/actions/workflows/test.yml?query=branch:v0.1.1
|
|
324
324
|
|
|
325
325
|
[coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/utils-async-parallel/main.svg
|
|
326
326
|
[coverage-url]: https://codecov.io/github/stdlib-js/utils-async-parallel?branch=main
|
|
@@ -332,8 +332,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
332
332
|
|
|
333
333
|
-->
|
|
334
334
|
|
|
335
|
-
[chat-image]: https://img.shields.io/
|
|
336
|
-
[chat-url]: https://
|
|
335
|
+
[chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
|
|
336
|
+
[chat-url]: https://stdlib.zulipchat.com
|
|
337
337
|
|
|
338
338
|
[stdlib]: https://github.com/stdlib-js/stdlib
|
|
339
339
|
|
package/dist/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
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) 2024 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 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* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'thisArg': {},\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, '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) 2024 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( 'parallel-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes functions in a provided array, limiting the number of concurrently pending functions.\n*\n* @private\n* @param {FunctionArray} fcns - array of functions\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 {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( fcns, opts, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tlen = fcns.length;\n\tdebug( 'Number of functions: %d', len );\n\n\tout = new Array( len );\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\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...\n\t\tif ( idx < maxIndex ) {\n\t\t\tnext(); // eslint-disable-line node/callback-return\n\t\t}\n\t}\n\t/**\n\t* Callback to invoke the next function.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar i;\n\n\t\tidx += 1;\n\n\t\t// Cache the current index value to allow storing results later:\n\t\ti = idx;\n\n\t\tfcns[ idx ].call( opts.thisArg, resolve );\n\n\t\t/**\n\t\t* Callback invoked once a provided function finishes.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [results] - results\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction resolve( error, results ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tout[ i ] = results;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next function.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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 functions.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing the functions.' );\n\t\t\treturn done( null, out );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = limit;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 isFunctionArray = require( '@stdlib/assert-is-function-array' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar format = require( '@stdlib/string-format' );\nvar PINF = require( '@stdlib/constants-float64-pinf' );\nvar validate = require( './validate.js' );\nvar limit = require( './limit.js' );\n\n\n// MAIN //\n\n/**\n* Returns a function to execute a set of functions in parallel.\n*\n* @param {FunctionArray} fcns - array of functions\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* @throws {TypeError} first argument must be an array of functions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} parallel function\n*\n* @example\n* function a( resolve ) {\n* setTimeout( onTimeout, 0 );\n* function onTimeout() {\n* resolve( null, 2 );\n* }\n* }\n*\n* function b( resolve ) {\n* setTimeout( onTimeout, 0 );\n* function onTimeout() {\n* resolve( null, 4 );\n* }\n* }\n*\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* // => [ 2, 4 ]\n* }\n*\n* var fcns = [ a, b ];\n*\n* var run = parallel.factory( fcns );\n*\n* run( done );\n*/\nfunction factory( fcns, options ) {\n\tvar opts;\n\tvar err;\n\n\tif ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an array of functions. Value: `%s`.', fcns ) );\n\t}\n\topts = {\n\t\t'limit': PINF\n\t};\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}\n\treturn parallel;\n\n\t/**\n\t* Executes a set of functions in parallel and returns an array of results.\n\t*\n\t* @private\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} must provide a function\n\t* @returns {void}\n\t*/\n\tfunction parallel( done ) {\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Callback argument must be a function. Value: `%s`.', done ) );\n\t\t}\n\t\treturn limit( fcns, opts, 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 {Array} [out] - output array\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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* Executes a set of functions in parallel.\n*\n* @param {FunctionArray} fcns - array of functions\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 {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an array of functions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {TypeError} callback argument must be a function\n* @returns {void}\n*\n* @example\n* var parallel = require( '@stdlib/utils-async-parallel' );\n*\n* function foo( resolve ) {\n* setTimeout( onTimeout, 300 );\n* function onTimeout() {\n* resolve( null, 'one' );\n* }\n* }\n*\n* function bar( resolve ) {\n* setTimeout( onTimeout, 100 );\n* function onTimeout() {\n* resolve( null, 'two' );\n* }\n* }\n*\n* function done( error, results ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( results );\n* // => [ 'one', 'two' ]\n* }\n*\n* var fcns = [ foo, bar ];\n*\n* parallel( fcns, done );\n*/\nfunction parallel( fcns, options, done ) {\n\tif ( arguments.length < 3 ) {\n\t\treturn factory( fcns )( options );\n\t}\n\tfactory( fcns, options )( done );\n}\n\n\n// EXPORTS //\n\nmodule.exports = parallel;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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* Execute a set of functions in parallel.\n*\n* @module @stdlib/utils-async-parallel\n*\n* @example\n* var parallel = require( '@stdlib/utils-async-parallel' );\n*\n* function foo( resolve ) {\n* setTimeout( onTimeout, 300 );\n* function onTimeout() {\n* resolve( null, 'one' );\n* }\n* }\n*\n* function bar( resolve ) {\n* setTimeout( onTimeout, 100 );\n* function onTimeout() {\n* resolve( null, 'two' );\n* }\n* }\n*\n* function done( error, results ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( results );\n* // => [ 'one', 'two' ]\n* }\n*\n* var fcns = [ foo, bar ];\n*\n* parallel( fcns, 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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
|
+
"sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 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* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'thisArg': {},\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, '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) 2024 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( 'parallel-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes functions in a provided array, limiting the number of concurrently pending functions.\n*\n* @private\n* @param {FunctionArray} fcns - array of functions\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 {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( fcns, opts, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tlen = fcns.length;\n\tdebug( 'Number of functions: %d', len );\n\n\tout = new Array( len ); // eslint-disable-line stdlib/no-new-array\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\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...\n\t\tif ( idx < maxIndex ) {\n\t\t\tnext(); // eslint-disable-line node/callback-return\n\t\t}\n\t}\n\t/**\n\t* Callback to invoke the next function.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar i;\n\n\t\tidx += 1;\n\n\t\t// Cache the current index value to allow storing results later:\n\t\ti = idx;\n\n\t\tfcns[ idx ].call( opts.thisArg, resolve );\n\n\t\t/**\n\t\t* Callback invoked once a provided function finishes.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [results] - results\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction resolve( error, results ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tout[ i ] = results;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next function.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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 functions.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing the functions.' );\n\t\t\treturn done( null, out );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = limit;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 isFunctionArray = require( '@stdlib/assert-is-function-array' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar format = require( '@stdlib/string-format' );\nvar PINF = require( '@stdlib/constants-float64-pinf' );\nvar validate = require( './validate.js' );\nvar limit = require( './limit.js' );\n\n\n// MAIN //\n\n/**\n* Returns a function to execute a set of functions in parallel.\n*\n* @param {FunctionArray} fcns - array of functions\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* @throws {TypeError} first argument must be an array of functions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} parallel function\n*\n* @example\n* function a( resolve ) {\n* setTimeout( onTimeout, 0 );\n* function onTimeout() {\n* resolve( null, 2 );\n* }\n* }\n*\n* function b( resolve ) {\n* setTimeout( onTimeout, 0 );\n* function onTimeout() {\n* resolve( null, 4 );\n* }\n* }\n*\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* // => [ 2, 4 ]\n* }\n*\n* var fcns = [ a, b ];\n*\n* var run = parallel.factory( fcns );\n*\n* run( done );\n*/\nfunction factory( fcns, options ) {\n\tvar opts;\n\tvar err;\n\n\tif ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an array of functions. Value: `%s`.', fcns ) );\n\t}\n\topts = {\n\t\t'limit': PINF\n\t};\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}\n\treturn parallel;\n\n\t/**\n\t* Executes a set of functions in parallel and returns an array of results.\n\t*\n\t* @private\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} must provide a function\n\t* @returns {void}\n\t*/\n\tfunction parallel( done ) {\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Callback argument must be a function. Value: `%s`.', done ) );\n\t\t}\n\t\treturn limit( fcns, opts, 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 {Array} [out] - output array\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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* Executes a set of functions in parallel.\n*\n* @param {FunctionArray} fcns - array of functions\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 {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an array of functions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {TypeError} callback argument must be a function\n* @returns {void}\n*\n* @example\n* function foo( resolve ) {\n* setTimeout( onTimeout, 300 );\n* function onTimeout() {\n* resolve( null, 'one' );\n* }\n* }\n*\n* function bar( resolve ) {\n* setTimeout( onTimeout, 100 );\n* function onTimeout() {\n* resolve( null, 'two' );\n* }\n* }\n*\n* function done( error, results ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( results );\n* // => [ 'one', 'two' ]\n* }\n*\n* var fcns = [ foo, bar ];\n*\n* parallel( fcns, done );\n*/\nfunction parallel( fcns, options, done ) {\n\tif ( arguments.length < 3 ) {\n\t\treturn factory( fcns )( options );\n\t}\n\tfactory( fcns, options )( done );\n}\n\n\n// EXPORTS //\n\nmodule.exports = parallel;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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* Execute a set of functions in parallel.\n*\n* @module @stdlib/utils-async-parallel\n*\n* @example\n* var parallel = require( '@stdlib/utils-async-parallel' );\n*\n* function foo( resolve ) {\n* setTimeout( onTimeout, 300 );\n* function onTimeout() {\n* resolve( null, 'one' );\n* }\n* }\n*\n* function bar( resolve ) {\n* setTimeout( onTimeout, 100 );\n* function onTimeout() {\n* resolve( null, 'two' );\n* }\n* }\n*\n* function done( error, results ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( results );\n* // => [ 'one', 'two' ]\n* }\n*\n* var fcns = [ foo, bar ];\n*\n* parallel( fcns, 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": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAoB,QAAS,oCAAqC,EAAE,YACpEC,EAAS,QAAS,uBAAwB,EA0B9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAMN,EAAUM,CAAQ,GAGnBL,EAAYK,EAAS,SAAU,IACnCD,EAAK,QAAUC,EAAQ,SAEnBL,EAAYK,EAAS,OAAQ,IACjCD,EAAK,MAAQC,EAAQ,MAChB,CAACJ,EAAmBG,EAAK,KAAM,GAC5B,IAAI,UAAWF,EAAQ,wEAAyE,Q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AkB,QAAS,kCAAmC,EAC9DC,EAAa,QAAS,4BAA6B,EACnDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAO,QAAS,gCAAiC,EACjDC,EAAW,IACXC,EAAQ,IA8CZ,SAASC,EAASC,EAAMC,EAAU,CACjC,IAAIC,EACAC,EAEJ,GAAK,CAACV,EAAiBO,CAAK,EAC3B,MAAM,IAAI,UAAWL,EAAQ,+EAAgFK,CAAK,CAAE,EAKrH,GAHAE,EAAO,CACN,MAASN,CACV,EACK,UAAU,OAAS,IACvBO,EAAMN,EAAUK,EAAMD,CAAQ,EACzBE,GACJ,MAAMA,EAGR,OAAOC,EAUP,SAASA,EAAUC,EAAO,CACzB,GAAK,CAACX,EAAYW,CAAK,EACtB,MAAM,IAAI,UAAWV,EAAQ,uEAAwEU,CAAK,CAAE,EAE7G,OAAOP,EAAOE,EAAME,EAAMI,CAAK,EAU/B,SAASA,EAAMC,EAAOC,EAAM,CAC3B,GAAKD,EACJ,OAAOF,EAAME,CAAM,EAEpBF,EAAM,KAAMG,CAAI,CACjB,CACD,CACD,CAKAhB,EAAO,QAAUO,IC7HjB,IAAAU,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAU,IA8Cd,SAASC,EAAUC,EAAMC,EAASC,EAAO,CACxC,GAAK,UAAU,OAAS,EACvB,OAAOJ,EAASE,CAAK,EAAGC,CAAQ,EAEjCH,EAASE,EAAMC,CAAQ,EAAGC,CAAK,CAChC,CAKAL,EAAO,QAAUE,ICrBjB,IAAII,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD",
|
|
6
6
|
"names": ["require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isPositiveInteger", "format", "validate", "opts", "options", "require_limit", "__commonJSMin", "exports", "module", "logger", "debug", "limit", "fcns", "opts", "done", "maxIndex", "count", "flg", "lim", "len", "idx", "out", "i", "next", "resolve", "error", "results", "clbk", "require_factory", "__commonJSMin", "exports", "module", "isFunctionArray", "isFunction", "format", "PINF", "validate", "limit", "factory", "fcns", "options", "opts", "err", "parallel", "done", "clbk", "error", "out", "require_main", "__commonJSMin", "exports", "module", "factory", "parallel", "fcns", "options", "done", "setReadOnly", "main", "factory"]
|
|
7
7
|
}
|
package/docs/types/index.d.ts
CHANGED
|
@@ -80,8 +80,6 @@ interface Parallel {
|
|
|
80
80
|
* @param clbk - callback to invoke upon completion
|
|
81
81
|
*
|
|
82
82
|
* @example
|
|
83
|
-
* var parallel = require( '@stdlib/utils-async-parallel' );
|
|
84
|
-
*
|
|
85
83
|
* function foo( clbk ) {
|
|
86
84
|
* setTimeout( onTimeout, 300 );
|
|
87
85
|
* function onTimeout() {
|
|
@@ -107,8 +105,8 @@ interface Parallel {
|
|
|
107
105
|
* var fcns = [ foo, bar ];
|
|
108
106
|
*
|
|
109
107
|
* var opts = {
|
|
110
|
-
*
|
|
111
|
-
*
|
|
108
|
+
* 'thisArg': {},
|
|
109
|
+
* 'limit': 2
|
|
112
110
|
* }
|
|
113
111
|
*
|
|
114
112
|
* parallel( fcns, opts, done );
|
|
@@ -218,8 +216,8 @@ interface Parallel {
|
|
|
218
216
|
* var fcns = [ a, b ];
|
|
219
217
|
*
|
|
220
218
|
* var opts = {
|
|
221
|
-
*
|
|
222
|
-
*
|
|
219
|
+
* 'thisArg': {},
|
|
220
|
+
* 'limit': 2
|
|
223
221
|
* }
|
|
224
222
|
*
|
|
225
223
|
* var run = parallel.factory( fcns, opts );
|
|
@@ -246,8 +244,6 @@ interface Parallel {
|
|
|
246
244
|
* @param clbk - callback to invoke upon completion
|
|
247
245
|
*
|
|
248
246
|
* @example
|
|
249
|
-
* var parallel = require( '@stdlib/utils-async-parallel' );
|
|
250
|
-
*
|
|
251
247
|
* function foo( clbk ) {
|
|
252
248
|
* setTimeout( onTimeout, 300 );
|
|
253
249
|
* function onTimeout() {
|
package/lib/limit.js
CHANGED
package/lib/main.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stdlib/utils-async-parallel",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Execute a set of functions in parallel.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": {
|
|
@@ -30,16 +30,16 @@
|
|
|
30
30
|
"url": "https://github.com/stdlib-js/stdlib/issues"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@stdlib/assert-has-own-property": "^0.2.
|
|
34
|
-
"@stdlib/assert-is-function": "^0.2.
|
|
35
|
-
"@stdlib/assert-is-function-array": "^0.2.
|
|
36
|
-
"@stdlib/assert-is-plain-object": "^0.2.
|
|
37
|
-
"@stdlib/assert-is-positive-integer": "^0.2.
|
|
38
|
-
"@stdlib/constants-float64-pinf": "^0.2.
|
|
39
|
-
"@stdlib/string-format": "^0.2.
|
|
40
|
-
"@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.
|
|
33
|
+
"@stdlib/assert-has-own-property": "^0.2.3",
|
|
34
|
+
"@stdlib/assert-is-function": "^0.2.3",
|
|
35
|
+
"@stdlib/assert-is-function-array": "^0.2.2",
|
|
36
|
+
"@stdlib/assert-is-plain-object": "^0.2.3",
|
|
37
|
+
"@stdlib/assert-is-positive-integer": "^0.2.3",
|
|
38
|
+
"@stdlib/constants-float64-pinf": "^0.2.3",
|
|
39
|
+
"@stdlib/string-format": "^0.2.3",
|
|
40
|
+
"@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.3",
|
|
41
41
|
"debug": "^2.6.9",
|
|
42
|
-
"@stdlib/error-tools-fmtprodmsg": "^0.2.
|
|
42
|
+
"@stdlib/error-tools-fmtprodmsg": "^0.2.3"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {},
|
|
45
45
|
"engines": {
|