@stdlib/utils-async-parallel 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/LICENSE +177 -0
- package/NOTICE +1 -0
- package/README.md +357 -0
- package/SECURITY.md +5 -0
- 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 +312 -0
- package/lib/factory.js +126 -0
- package/lib/index.js +70 -0
- package/lib/limit.js +138 -0
- package/lib/main.js +81 -0
- package/lib/validate.js +71 -0
- package/package.json +81 -0
package/lib/validate.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2024 The Stdlib Authors.
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
'use strict';
|
|
20
|
+
|
|
21
|
+
// MODULES //
|
|
22
|
+
|
|
23
|
+
var isObject = require( '@stdlib/assert-is-plain-object' );
|
|
24
|
+
var hasOwnProp = require( '@stdlib/assert-has-own-property' );
|
|
25
|
+
var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive;
|
|
26
|
+
var format = require( '@stdlib/string-format' );
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
// MAIN //
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Validates function options.
|
|
33
|
+
*
|
|
34
|
+
* @private
|
|
35
|
+
* @param {Object} opts - destination object
|
|
36
|
+
* @param {Options} options - function options
|
|
37
|
+
* @param {*} [options.thisArg] - execution context
|
|
38
|
+
* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time
|
|
39
|
+
* @returns {(Error|null)} null or an error object
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* var opts = {};
|
|
43
|
+
* var options = {
|
|
44
|
+
* 'thisArg': {},
|
|
45
|
+
* 'limit': 10
|
|
46
|
+
* };
|
|
47
|
+
* var err = validate( opts, options );
|
|
48
|
+
* if ( err ) {
|
|
49
|
+
* throw err;
|
|
50
|
+
* }
|
|
51
|
+
*/
|
|
52
|
+
function validate( opts, options ) {
|
|
53
|
+
if ( !isObject( options ) ) {
|
|
54
|
+
return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
|
|
55
|
+
}
|
|
56
|
+
if ( hasOwnProp( options, 'thisArg' ) ) {
|
|
57
|
+
opts.thisArg = options.thisArg;
|
|
58
|
+
}
|
|
59
|
+
if ( hasOwnProp( options, 'limit' ) ) {
|
|
60
|
+
opts.limit = options.limit;
|
|
61
|
+
if ( !isPositiveInteger( opts.limit ) ) {
|
|
62
|
+
return new TypeError( format( 'invalid option. `%s` option must be a positive integer. Option: `%s`.', 'limit', opts.limit ) );
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
// EXPORTS //
|
|
70
|
+
|
|
71
|
+
module.exports = validate;
|
package/package.json
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@stdlib/utils-async-parallel",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Execute a set of functions in parallel.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"author": {
|
|
7
|
+
"name": "The Stdlib Authors",
|
|
8
|
+
"url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
|
|
9
|
+
},
|
|
10
|
+
"contributors": [
|
|
11
|
+
{
|
|
12
|
+
"name": "The Stdlib Authors",
|
|
13
|
+
"url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
|
|
14
|
+
}
|
|
15
|
+
],
|
|
16
|
+
"main": "./lib",
|
|
17
|
+
"directories": {
|
|
18
|
+
"doc": "./docs",
|
|
19
|
+
"lib": "./lib",
|
|
20
|
+
"dist": "./dist"
|
|
21
|
+
},
|
|
22
|
+
"types": "./docs/types",
|
|
23
|
+
"scripts": {},
|
|
24
|
+
"homepage": "https://stdlib.io",
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "git://github.com/stdlib-js/utils-async-parallel.git"
|
|
28
|
+
},
|
|
29
|
+
"bugs": {
|
|
30
|
+
"url": "https://github.com/stdlib-js/stdlib/issues"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@stdlib/assert-has-own-property": "^0.2.2",
|
|
34
|
+
"@stdlib/assert-is-function": "^0.2.2",
|
|
35
|
+
"@stdlib/assert-is-function-array": "^0.2.1",
|
|
36
|
+
"@stdlib/assert-is-plain-object": "^0.2.2",
|
|
37
|
+
"@stdlib/assert-is-positive-integer": "^0.2.2",
|
|
38
|
+
"@stdlib/constants-float64-pinf": "^0.2.2",
|
|
39
|
+
"@stdlib/string-format": "^0.2.2",
|
|
40
|
+
"@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2",
|
|
41
|
+
"debug": "^2.6.9",
|
|
42
|
+
"@stdlib/error-tools-fmtprodmsg": "^0.2.2"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {},
|
|
45
|
+
"engines": {
|
|
46
|
+
"node": ">=0.10.0",
|
|
47
|
+
"npm": ">2.7.0"
|
|
48
|
+
},
|
|
49
|
+
"os": [
|
|
50
|
+
"aix",
|
|
51
|
+
"darwin",
|
|
52
|
+
"freebsd",
|
|
53
|
+
"linux",
|
|
54
|
+
"macos",
|
|
55
|
+
"openbsd",
|
|
56
|
+
"sunos",
|
|
57
|
+
"win32",
|
|
58
|
+
"windows"
|
|
59
|
+
],
|
|
60
|
+
"keywords": [
|
|
61
|
+
"stdlib",
|
|
62
|
+
"stdutils",
|
|
63
|
+
"stdutil",
|
|
64
|
+
"utilities",
|
|
65
|
+
"utils",
|
|
66
|
+
"util",
|
|
67
|
+
"async",
|
|
68
|
+
"parallel",
|
|
69
|
+
"concurrent",
|
|
70
|
+
"parallelism",
|
|
71
|
+
"functions",
|
|
72
|
+
"fcns",
|
|
73
|
+
"run",
|
|
74
|
+
"control",
|
|
75
|
+
"flow"
|
|
76
|
+
],
|
|
77
|
+
"funding": {
|
|
78
|
+
"type": "opencollective",
|
|
79
|
+
"url": "https://opencollective.com/stdlib"
|
|
80
|
+
}
|
|
81
|
+
}
|