@trenskow/parallel 0.0.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/.eslintrc.js ADDED
@@ -0,0 +1,50 @@
1
+ module.exports = {
2
+ 'env': {
3
+ 'es6': true,
4
+ 'node': true,
5
+ 'mocha': true
6
+ },
7
+ 'parserOptions': {
8
+ 'ecmaVersion': 2017,
9
+ 'sourceType': 'module'
10
+ },
11
+ 'extends': 'eslint:recommended',
12
+ 'rules': {
13
+ 'indent': [
14
+ 'error',
15
+ 'tab'
16
+ ],
17
+ 'linebreak-style': [
18
+ 'error',
19
+ 'unix'
20
+ ],
21
+ 'quotes': [
22
+ 'error',
23
+ 'single'
24
+ ],
25
+ 'semi': [
26
+ 'error',
27
+ 'always'
28
+ ],
29
+ 'no-console': [
30
+ 'error', {
31
+ 'allow': [
32
+ 'warn',
33
+ 'error',
34
+ 'info'
35
+ ]
36
+ }
37
+ ],
38
+ 'no-unused-vars': [
39
+ 'error', {
40
+ 'argsIgnorePattern': '^_'
41
+ }
42
+ ],
43
+ 'no-empty': [
44
+ 'error', {
45
+ 'allowEmptyCatch': true
46
+ }
47
+ ],
48
+ 'require-atomic-updates': 'off'
49
+ }
50
+ };
package/LICENSE ADDED
@@ -0,0 +1,9 @@
1
+ Copyright 2022 Kristian Trenskow
2
+
3
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4
+
5
+ 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6
+
7
+ 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8
+
9
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/README.md ADDED
@@ -0,0 +1,30 @@
1
+ @trenskow/parallel
2
+ ----
3
+
4
+ A small library for doing async tasks in parallel.
5
+
6
+ # Usage
7
+
8
+ Usage is pretty simple – see an example below.
9
+
10
+ ````javascript
11
+ import parallel from '@trenskow/parallel';
12
+
13
+ const result = await parallel([
14
+ myFirstPromise,
15
+ mySecondPromise,
16
+ ...
17
+ ]);
18
+ ````
19
+
20
+ ## Compared to `Promise.all`
21
+
22
+ On the surface this looks a lot like `Promise.all`, but there is one crucial difference.
23
+
24
+ Where `Promise.all` settles fast, meaning if a promise is rejected then `Promise.all` will reject immediate – leaving the other promises to be potentially resolved.
25
+
26
+ This library is for when you want the opposite behavior, when you want all promises to be settled before the entire thing is resolved or rejected.
27
+
28
+ # LICENSE
29
+
30
+ See license in LICENSE
package/index.js ADDED
@@ -0,0 +1,12 @@
1
+ // Created 2022-04-10 by Kristian Trenskow
2
+
3
+ const parallel = async (promises) => {
4
+ if (!Array.isArray(promises)) return await parallel([promises]);
5
+ return (await Promise.allSettled(promises.map((promise) => Promise.resolve(promise))))
6
+ .map((result) => {
7
+ if (result.status === 'rejected') throw result.reason;
8
+ return result.value;
9
+ });
10
+ };
11
+
12
+ export default parallel;
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "@trenskow/parallel",
3
+ "version": "0.0.1",
4
+ "description": "A small library for doing async tasks in parallel.",
5
+ "main": "index.js",
6
+ "type": "module",
7
+ "scripts": {
8
+ "test": "echo \"Error: no test specified\" && exit 1"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/trenskow/parallel.git"
13
+ },
14
+ "keywords": [
15
+ "parallel",
16
+ "async",
17
+ "promise",
18
+ "await"
19
+ ],
20
+ "author": "Kristian Trenskow <trenskow@me.com>",
21
+ "license": "BSD-2-Clause",
22
+ "bugs": {
23
+ "url": "https://github.com/trenskow/parallel/issues"
24
+ },
25
+ "homepage": "https://github.com/trenskow/parallel#readme"
26
+ }