xaa 2.0.0 → 3.0.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 +199 -9
- package/README.md +1 -1
- package/{dist-esm → dist}/index.js +0 -1
- package/dist/index.js.map +1 -0
- package/package.json +19 -21
- package/dist-cjs/index.cjs +0 -437
- package/dist-cjs/index.cjs.map +0 -1
- package/dist-cjs/index.js.map +0 -1
- package/dist-cjs/tsconfig.cjs.tsbuildinfo +0 -1
- package/dist-esm/index.d.ts +0 -303
- package/dist-esm/index.js.map +0 -1
- package/dist-esm/tsconfig.esm.tsbuildinfo +0 -1
- /package/{dist-cjs → dist}/index.d.ts +0 -0
package/LICENSE
CHANGED
|
@@ -1,11 +1,201 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2019 Joel Chen
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,MAAM,MAAM,QAAQ,CAAC;AAO5B;;;;;GAKG;AACH,MAAM,UAAU,SAAS,CAAI,CAAM;IACjC,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,KAAK,IAAI,OAAO,CAAC,CAAC,IAAI,KAAK,UAAU,IAAI,OAAO,CAAC,CAAC,KAAK,KAAK,UAAU,CAAC;AACjG,CAAC;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
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"engines": {
|
|
5
|
-
"node": ">=
|
|
5
|
+
"node": ">=22.12.0"
|
|
6
6
|
},
|
|
7
7
|
"description": "async/await/Promise helpers - delay, defer, timeout, each, map, filter",
|
|
8
8
|
"type": "module",
|
|
9
|
-
"types": "dist
|
|
10
|
-
"main": "dist
|
|
11
|
-
"module": "dist-esm/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"main": "./dist/index.js",
|
|
12
11
|
"exports": {
|
|
13
12
|
".": {
|
|
14
|
-
"
|
|
15
|
-
"
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"default": "./dist/index.js"
|
|
16
15
|
},
|
|
17
16
|
"./package.json": "./package.json"
|
|
18
17
|
},
|
|
18
|
+
"sideEffects": false,
|
|
19
19
|
"scripts": {
|
|
20
|
-
"build": "
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"build:cjs": "tsc --build tsconfig.cjs.json",
|
|
24
|
-
"build:2cjs": "ts2mjs --cjs --skip-ts --remove-source dist-cjs",
|
|
25
|
-
"test": "xrun [vitest, demo:cjs, demo:esm]",
|
|
20
|
+
"build": "rm -rf dist && tsc -p tsconfig.json",
|
|
21
|
+
"test": "npm run vitest && npm run demo:cjs && npm run demo:esm",
|
|
22
|
+
"ci:check": "tsc --noEmit -p tsconfig.json && npm test",
|
|
26
23
|
"vitest": "vitest run",
|
|
27
24
|
"coverage": "vitest run --coverage",
|
|
28
25
|
"format": "prettier --write src test demo vitest.config.ts",
|
|
29
26
|
"demo:cjs": "cd demo/sample-1-cjs && fyn install && node demo.cjs",
|
|
30
27
|
"demo:esm": "cd demo/sample-1-esm && fyn install && node demo.js",
|
|
31
|
-
"prepublishOnly": "
|
|
28
|
+
"prepublishOnly": "npm run coverage && npm run build",
|
|
32
29
|
"docs": "typedoc --gitRevision $(git rev-list -1 HEAD src) --out docs src",
|
|
33
30
|
"postpack": "publish-util-postpack"
|
|
34
31
|
},
|
|
35
|
-
"homepage": "https://
|
|
32
|
+
"homepage": "https://github.com/jchip/fynjs/tree/main/packages/xaa",
|
|
33
|
+
"bugs": {
|
|
34
|
+
"url": "https://github.com/jchip/fynjs/issues"
|
|
35
|
+
},
|
|
36
36
|
"repository": {
|
|
37
37
|
"type": "git",
|
|
38
|
-
"url": "https://github.com/jchip/
|
|
38
|
+
"url": "git+https://github.com/jchip/fynjs.git",
|
|
39
|
+
"directory": "packages/xaa"
|
|
39
40
|
},
|
|
40
41
|
"keywords": [
|
|
41
42
|
"async",
|
|
@@ -51,12 +52,9 @@
|
|
|
51
52
|
"filter"
|
|
52
53
|
],
|
|
53
54
|
"files": [
|
|
54
|
-
"dist
|
|
55
|
-
"dist-esm"
|
|
55
|
+
"dist"
|
|
56
56
|
],
|
|
57
57
|
"author": "Joel Chen",
|
|
58
58
|
"license": "Apache-2.0",
|
|
59
|
-
"dependencies": {
|
|
60
|
-
"tslib": "^2.6.2"
|
|
61
|
-
}
|
|
59
|
+
"dependencies": {}
|
|
62
60
|
}
|
package/dist-cjs/index.cjs
DELETED
|
@@ -1,437 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* @packageDocumentation
|
|
4
|
-
* @module index
|
|
5
|
-
*/
|
|
6
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
7
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
8
|
-
};
|
|
9
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.TimeoutRunner = exports.TimeoutError = exports.Defer = void 0;
|
|
11
|
-
exports.isPromise = isPromise;
|
|
12
|
-
exports.makeDefer = makeDefer;
|
|
13
|
-
exports.defer = makeDefer;
|
|
14
|
-
exports.delay = delay;
|
|
15
|
-
exports.timeout = timeout;
|
|
16
|
-
exports.runTimeout = runTimeout;
|
|
17
|
-
exports.mapSeries = mapSeries;
|
|
18
|
-
exports.map = map;
|
|
19
|
-
exports.each = each;
|
|
20
|
-
exports.filter = filter;
|
|
21
|
-
exports.tryCatch = tryCatch;
|
|
22
|
-
exports.try = tryCatch;
|
|
23
|
-
exports.wrap = wrap;
|
|
24
|
-
/* eslint-disable max-statements, @typescript-eslint/ban-types, max-params, complexity */
|
|
25
|
-
const assert_1 = __importDefault(require("assert"));
|
|
26
|
-
/**
|
|
27
|
-
* check if something is a promise
|
|
28
|
-
*
|
|
29
|
-
* @param p
|
|
30
|
-
* @returns true or false
|
|
31
|
-
*/
|
|
32
|
-
function isPromise(p) {
|
|
33
|
-
return p && p.then && p.catch && typeof p.then === "function" && typeof p.catch === "function";
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Defer object for fulfilling a promise later in other events
|
|
37
|
-
*
|
|
38
|
-
* To use, use `xaa.makeDefer` or its alias `xaa.defeer`.
|
|
39
|
-
*
|
|
40
|
-
*/
|
|
41
|
-
class Defer {
|
|
42
|
-
/**
|
|
43
|
-
* construct Defer
|
|
44
|
-
*
|
|
45
|
-
* @param ThePromise optional promise constructor
|
|
46
|
-
*/
|
|
47
|
-
constructor(ThePromise = global.Promise) {
|
|
48
|
-
this.promise = new ThePromise((resolve, reject) => {
|
|
49
|
-
this.resolve = resolve;
|
|
50
|
-
this.reject = reject;
|
|
51
|
-
});
|
|
52
|
-
// Not declaring (err, result) explicitly for standard node.js callback.
|
|
53
|
-
// we can't be sure if user's API expects callback that
|
|
54
|
-
// should have a second arg for result.
|
|
55
|
-
this.done = (err, ...args) => {
|
|
56
|
-
if (err)
|
|
57
|
-
this.reject(err);
|
|
58
|
-
else
|
|
59
|
-
this.resolve(args[0]);
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
exports.Defer = Defer;
|
|
64
|
-
/**
|
|
65
|
-
* Create a promise Defer object
|
|
66
|
-
*
|
|
67
|
-
* Sample:
|
|
68
|
-
*
|
|
69
|
-
* ```js
|
|
70
|
-
* async function waitEvent() {
|
|
71
|
-
* const defer = xaa.makeDefer();
|
|
72
|
-
* someThing.on("event", (data) => defer.resolve(data))
|
|
73
|
-
* return defer.promise;
|
|
74
|
-
* }
|
|
75
|
-
* ```
|
|
76
|
-
*
|
|
77
|
-
* @param ThePromise - optional Promise constructor.
|
|
78
|
-
* @returns Defer instance
|
|
79
|
-
*/
|
|
80
|
-
function makeDefer(ThePromise = global.Promise) {
|
|
81
|
-
return new Defer(ThePromise);
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* The error xaa.timeout will throw if operation timed out
|
|
85
|
-
*/
|
|
86
|
-
class TimeoutError extends Error {
|
|
87
|
-
constructor(msg) {
|
|
88
|
-
super(msg);
|
|
89
|
-
this.name = "TimeoutError";
|
|
90
|
-
(0, assert_1.default)(msg);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
exports.TimeoutError = TimeoutError;
|
|
94
|
-
async function delay(delayMs, valOrFunc) {
|
|
95
|
-
await new Promise(resolve => setTimeout(resolve, delayMs));
|
|
96
|
-
return typeof valOrFunc === "function" ? /* lazily */ valOrFunc() : valOrFunc;
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* TimeoutRunner for running tasks (promises) with a timeout
|
|
100
|
-
*
|
|
101
|
-
* Please use `xaa.timeout` or `xaa.runTimeout` APIs instead.
|
|
102
|
-
*/
|
|
103
|
-
class TimeoutRunner {
|
|
104
|
-
/**
|
|
105
|
-
* constructor
|
|
106
|
-
* @param maxMs - number of milliseconds to allow tasks to run
|
|
107
|
-
* @param rejectMsg - message to reject with when timeout triggers
|
|
108
|
-
* @param options - TimeoutRunnerOptions
|
|
109
|
-
*/
|
|
110
|
-
constructor(maxMs, rejectMsg, options) {
|
|
111
|
-
this.maxMs = maxMs;
|
|
112
|
-
this.rejectMsg = rejectMsg;
|
|
113
|
-
this.defer = makeDefer(options.Promise);
|
|
114
|
-
this.ThePromise = options.Promise;
|
|
115
|
-
this.TimeoutError = options.TimeoutError;
|
|
116
|
-
this.timeout = setTimeout(() => this.defer.reject(new this.TimeoutError(rejectMsg)), maxMs);
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* check if runner has failed with error
|
|
120
|
-
*
|
|
121
|
-
* @returns has error flag
|
|
122
|
-
*/
|
|
123
|
-
hasError() {
|
|
124
|
-
return this.hasOwnProperty("error");
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* check if runner has finished with result
|
|
128
|
-
*
|
|
129
|
-
* @returns has result flag
|
|
130
|
-
*/
|
|
131
|
-
hasResult() {
|
|
132
|
-
return this.hasOwnProperty("result");
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Run tasks
|
|
136
|
-
*
|
|
137
|
-
* @param tasks - Promise or function that returns Promise, or array of them.
|
|
138
|
-
* @returns Promise to wait for tasks to complete, or timeout error.
|
|
139
|
-
*/
|
|
140
|
-
async run(tasks) {
|
|
141
|
-
const process = async (x) => (typeof x === "function" ? x() : x);
|
|
142
|
-
// Cast below is due in part to https://github.com/microsoft/TypeScript/issues/17002
|
|
143
|
-
const arrTasks = !Array.isArray(tasks)
|
|
144
|
-
? process(tasks)
|
|
145
|
-
: this.ThePromise.all(tasks.map(process));
|
|
146
|
-
try {
|
|
147
|
-
const r = await this.ThePromise.race([arrTasks, this.defer.promise]);
|
|
148
|
-
this.clear();
|
|
149
|
-
this.result = r;
|
|
150
|
-
return r;
|
|
151
|
-
}
|
|
152
|
-
catch (err) {
|
|
153
|
-
this.clear();
|
|
154
|
-
this.error = err;
|
|
155
|
-
throw err;
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* Cancel the operation and reject with msg
|
|
160
|
-
*
|
|
161
|
-
* @param msg - cancel message
|
|
162
|
-
*/
|
|
163
|
-
cancel(msg = "xaa TimeoutRunner operation cancelled") {
|
|
164
|
-
this.clear();
|
|
165
|
-
this.defer.reject(new this.TimeoutError(msg));
|
|
166
|
-
}
|
|
167
|
-
/** Explicitly clear the setTimeout handle */
|
|
168
|
-
clear() {
|
|
169
|
-
if (this.timeout) {
|
|
170
|
-
clearTimeout(this.timeout);
|
|
171
|
-
this.timeout = null;
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
/**
|
|
175
|
-
* Check if runner is done
|
|
176
|
-
*
|
|
177
|
-
* @returns is done flag
|
|
178
|
-
*/
|
|
179
|
-
isDone() {
|
|
180
|
-
return this.hasResult() || this.hasError();
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
exports.TimeoutRunner = TimeoutRunner;
|
|
184
|
-
/**
|
|
185
|
-
* Create a TimeoutRunner to run tasks (promises) with timeout
|
|
186
|
-
*
|
|
187
|
-
* Sample:
|
|
188
|
-
*
|
|
189
|
-
* ```js
|
|
190
|
-
* await xaa.timeout(1000, "timeout fetching data").run(() => fetch(url))
|
|
191
|
-
* ```
|
|
192
|
-
*
|
|
193
|
-
* with promises:
|
|
194
|
-
*
|
|
195
|
-
* ```js
|
|
196
|
-
* await xaa.timout(1000).run([promise1, promise2])
|
|
197
|
-
* ```
|
|
198
|
-
*
|
|
199
|
-
* @param maxMs - number of milliseconds to allow tasks to run
|
|
200
|
-
* @param rejectMsg - message to reject with when timeout triggers
|
|
201
|
-
* @returns TimeoutRunner object
|
|
202
|
-
*/
|
|
203
|
-
function timeout(maxMs, rejectMsg = "xaa TimeoutRunner operation timed out", options = { TimeoutError: TimeoutError, Promise: global.Promise }) {
|
|
204
|
-
return new TimeoutRunner(maxMs, rejectMsg, options);
|
|
205
|
-
}
|
|
206
|
-
async function runTimeout(tasks, maxMs, rejectMsg, options) {
|
|
207
|
-
return await timeout(maxMs, rejectMsg, options).run(tasks);
|
|
208
|
-
}
|
|
209
|
-
/**
|
|
210
|
-
* create map context
|
|
211
|
-
*
|
|
212
|
-
* @param array - array to map
|
|
213
|
-
* @returns map context
|
|
214
|
-
*/
|
|
215
|
-
function createMapContext(array) {
|
|
216
|
-
return {
|
|
217
|
-
array,
|
|
218
|
-
failed: false,
|
|
219
|
-
assertNoFailure() {
|
|
220
|
-
if (this.failed) {
|
|
221
|
-
throw new Error("assertNoFailure");
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
};
|
|
225
|
-
}
|
|
226
|
-
/**
|
|
227
|
-
* async map for array that supports concurrency
|
|
228
|
-
*
|
|
229
|
-
* Use by xaa.map internally.
|
|
230
|
-
*
|
|
231
|
-
* @param array array to map, if any item is promise-like, it will be resolved first.
|
|
232
|
-
* @param func mapper callback
|
|
233
|
-
* @param options MapOptions
|
|
234
|
-
* @returns promise with mapped result
|
|
235
|
-
*/
|
|
236
|
-
function multiMap(array, func, options) {
|
|
237
|
-
const awaited = new Array(array.length);
|
|
238
|
-
let error;
|
|
239
|
-
let completedCount = 0;
|
|
240
|
-
let freeSlots = options.concurrency;
|
|
241
|
-
let index = 0;
|
|
242
|
-
const iterator = Symbol.iterator in array && typeof array[Symbol.iterator] === "function"
|
|
243
|
-
? array[Symbol.iterator]()
|
|
244
|
-
: null;
|
|
245
|
-
let totalCount = iterator ? Infinity : array.length;
|
|
246
|
-
const context = createMapContext(array);
|
|
247
|
-
const defer = makeDefer();
|
|
248
|
-
const fail = (err) => {
|
|
249
|
-
context.failed = true;
|
|
250
|
-
if (!error) {
|
|
251
|
-
error = err; // Safe because of the following line:
|
|
252
|
-
error.partial = awaited;
|
|
253
|
-
defer.reject(error);
|
|
254
|
-
}
|
|
255
|
-
};
|
|
256
|
-
const mapNext = () => {
|
|
257
|
-
// important to check this here, so an empty input array immediately
|
|
258
|
-
// gets resolved with an empty result.
|
|
259
|
-
if (!error && completedCount === totalCount) {
|
|
260
|
-
return defer.resolve(awaited);
|
|
261
|
-
}
|
|
262
|
-
if (error || freeSlots <= 0 || index >= totalCount) {
|
|
263
|
-
return null;
|
|
264
|
-
}
|
|
265
|
-
const ir = iterator && iterator.next();
|
|
266
|
-
/* c8 ignore next 7 */
|
|
267
|
-
if (ir && ir.done) {
|
|
268
|
-
if (totalCount !== index) {
|
|
269
|
-
totalCount = index;
|
|
270
|
-
return mapNext();
|
|
271
|
-
}
|
|
272
|
-
return null;
|
|
273
|
-
}
|
|
274
|
-
freeSlots--;
|
|
275
|
-
const pendingIx = index++;
|
|
276
|
-
const save = (x) => {
|
|
277
|
-
completedCount++;
|
|
278
|
-
freeSlots++;
|
|
279
|
-
awaited[pendingIx] = x;
|
|
280
|
-
mapNext();
|
|
281
|
-
};
|
|
282
|
-
const handleRet = res => {
|
|
283
|
-
if (isPromise(res)) {
|
|
284
|
-
res.then(save, fail);
|
|
285
|
-
return mapNext();
|
|
286
|
-
}
|
|
287
|
-
else {
|
|
288
|
-
return save(res);
|
|
289
|
-
}
|
|
290
|
-
};
|
|
291
|
-
const item = ir ? ir.value : array[pendingIx];
|
|
292
|
-
if (isPromise(item)) {
|
|
293
|
-
return item.then(val => {
|
|
294
|
-
return handleRet(func.call(options.thisArg, val, pendingIx, context));
|
|
295
|
-
}, fail);
|
|
296
|
-
}
|
|
297
|
-
else {
|
|
298
|
-
try {
|
|
299
|
-
return handleRet(func.call(options.thisArg, item, pendingIx, context));
|
|
300
|
-
}
|
|
301
|
-
catch (err) {
|
|
302
|
-
return fail(err);
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
};
|
|
306
|
-
//
|
|
307
|
-
// Should not use setTimeout for next:
|
|
308
|
-
//
|
|
309
|
-
// Top level code in async functions before any await statements, execute synchronously.
|
|
310
|
-
//
|
|
311
|
-
// Similar to that setting up promises is sync, and then the
|
|
312
|
-
// fulfilment of them is async, meaning their .then are called.
|
|
313
|
-
//
|
|
314
|
-
mapNext();
|
|
315
|
-
return defer.promise;
|
|
316
|
-
}
|
|
317
|
-
async function mapSeries(array, func, options) {
|
|
318
|
-
const awaited = new Array();
|
|
319
|
-
const context = createMapContext(array);
|
|
320
|
-
let i = 0;
|
|
321
|
-
try {
|
|
322
|
-
for (const element of array) {
|
|
323
|
-
const item = isPromise(element) ? await element : element;
|
|
324
|
-
awaited[i] = await func.call(options && options.thisArg, item, i, context);
|
|
325
|
-
i++;
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
catch (err) {
|
|
329
|
-
context.failed = true;
|
|
330
|
-
err.partial = awaited;
|
|
331
|
-
throw err;
|
|
332
|
-
}
|
|
333
|
-
return awaited;
|
|
334
|
-
}
|
|
335
|
-
/**
|
|
336
|
-
* async map array with concurrency
|
|
337
|
-
*
|
|
338
|
-
* - intended to be similar to `bluebird.map`
|
|
339
|
-
*
|
|
340
|
-
* @param array array to map, if any item is promise-like, it will be resolved first.
|
|
341
|
-
* @param func - callback to map values from the array
|
|
342
|
-
* @param options - MapOptions
|
|
343
|
-
* @returns promise with mapped result
|
|
344
|
-
*/
|
|
345
|
-
async function map(array, func, options = { concurrency: 50 }) {
|
|
346
|
-
(0, assert_1.default)(Array.isArray(array), `xaa.map expecting an array but got ${typeof array}`);
|
|
347
|
-
if (options.concurrency > 1) {
|
|
348
|
-
return multiMap(array, func, options);
|
|
349
|
-
}
|
|
350
|
-
else {
|
|
351
|
-
return mapSeries(array, func, options);
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
/**
|
|
355
|
-
* async version of array.forEach
|
|
356
|
-
* - iterate through array and await call func with each element and index
|
|
357
|
-
*
|
|
358
|
-
* Sample:
|
|
359
|
-
*
|
|
360
|
-
* ```js
|
|
361
|
-
* await xaa.each([1, 2, 3], async val => await xaa.delay(val))
|
|
362
|
-
* ```
|
|
363
|
-
*
|
|
364
|
-
* @param array array to each
|
|
365
|
-
* @param func callback for each
|
|
366
|
-
*/
|
|
367
|
-
async function each(array, func) {
|
|
368
|
-
let i = 0;
|
|
369
|
-
const items = [];
|
|
370
|
-
for (const element of array) {
|
|
371
|
-
const item = isPromise(element) ? await element : element;
|
|
372
|
-
items.push(item);
|
|
373
|
-
await func(item, i);
|
|
374
|
-
i++;
|
|
375
|
-
}
|
|
376
|
-
return items;
|
|
377
|
-
}
|
|
378
|
-
/**
|
|
379
|
-
* async filter array
|
|
380
|
-
*
|
|
381
|
-
* Sample:
|
|
382
|
-
*
|
|
383
|
-
* ```js
|
|
384
|
-
* await xaa.filter([1, 2, 3], async val => await validateResult(val))
|
|
385
|
-
* ```
|
|
386
|
-
*
|
|
387
|
-
* Beware: concurrency is fixed to 1.
|
|
388
|
-
*
|
|
389
|
-
* @param array array to filter
|
|
390
|
-
* @param func callback for filter
|
|
391
|
-
* @returns filtered result
|
|
392
|
-
*/
|
|
393
|
-
async function filter(array, func) {
|
|
394
|
-
const filtered = [];
|
|
395
|
-
for (let i = 0; i < array.length; i++) {
|
|
396
|
-
const x = await func(array[i], i);
|
|
397
|
-
if (x)
|
|
398
|
-
filtered.push(array[i]);
|
|
399
|
-
}
|
|
400
|
-
return filtered;
|
|
401
|
-
}
|
|
402
|
-
/**
|
|
403
|
-
* try to:
|
|
404
|
-
* - await a promise
|
|
405
|
-
* - call and await function that returns a promise
|
|
406
|
-
*
|
|
407
|
-
* If exception occur, then return `valOrFunc`
|
|
408
|
-
*
|
|
409
|
-
* - if `valOrFunc` is a function, then return `valOrFunc(err)`
|
|
410
|
-
*
|
|
411
|
-
* @param funcOrPromise function or promise to try
|
|
412
|
-
* @param valOrFunc value, or callback to get value, to return if `func` throws
|
|
413
|
-
* @returns result, `valOrFunc`, or `valOrFunc(err)`.
|
|
414
|
-
*/
|
|
415
|
-
async function tryCatch(funcOrPromise, valOrFunc) {
|
|
416
|
-
try {
|
|
417
|
-
if (isPromise(funcOrPromise)) {
|
|
418
|
-
return await funcOrPromise;
|
|
419
|
-
}
|
|
420
|
-
return await funcOrPromise();
|
|
421
|
-
}
|
|
422
|
-
catch (err) {
|
|
423
|
-
return typeof valOrFunc === "function" ? valOrFunc(err) : valOrFunc;
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
/**
|
|
427
|
-
* Wrap the calling of a function into async/await (promise) context
|
|
428
|
-
* - intended to be similar to `bluebird.try`
|
|
429
|
-
*
|
|
430
|
-
* @param func function to wrap in async context
|
|
431
|
-
* @param args arguments to pass to `func`
|
|
432
|
-
* @returns result from `func`
|
|
433
|
-
*/
|
|
434
|
-
async function wrap(func, ...args2) {
|
|
435
|
-
return func(...args2);
|
|
436
|
-
}
|
|
437
|
-
//# sourceMappingURL=index.cjs.map
|
package/dist-cjs/index.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["index.js"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;"}
|
package/dist-cjs/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AA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C,CAAC,CAAC,CAAE,SAAiB,CAAC;IAC/E,CAAC;AACH,CAAC;AAID;;;;;;;GAOG;AACI,KAAK,UAAU,IAAI,CACxB,IAAO,EACP,GAAG,KAAoB;IAEvB,OAAO,IAAI,CAAC,GAAG,KAAK,CAAC,CAAC;AACxB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"root":["../src/index.ts"],"version":"5.9.3"}
|
package/dist-esm/index.d.ts
DELETED
|
@@ -1,303 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @packageDocumentation
|
|
3
|
-
* @module index
|
|
4
|
-
*/
|
|
5
|
-
type Consumer<T> = (item: T, index?: number) => unknown;
|
|
6
|
-
type FuncProducer<T> = () => T | Promise<T>;
|
|
7
|
-
type Producer<T> = Promise<T> | FuncProducer<T>;
|
|
8
|
-
type Predicate<T> = (item: T, index?: number) => boolean | Promise<boolean>;
|
|
9
|
-
/**
|
|
10
|
-
* check if something is a promise
|
|
11
|
-
*
|
|
12
|
-
* @param p
|
|
13
|
-
* @returns true or false
|
|
14
|
-
*/
|
|
15
|
-
export declare function isPromise<T>(p: any): p is Promise<T>;
|
|
16
|
-
/**
|
|
17
|
-
* Defer object for fulfilling a promise later in other events
|
|
18
|
-
*
|
|
19
|
-
* To use, use `xaa.makeDefer` or its alias `xaa.defeer`.
|
|
20
|
-
*
|
|
21
|
-
*/
|
|
22
|
-
export declare class Defer<T> {
|
|
23
|
-
/**
|
|
24
|
-
* construct Defer
|
|
25
|
-
*
|
|
26
|
-
* @param ThePromise optional promise constructor
|
|
27
|
-
*/
|
|
28
|
-
constructor(ThePromise?: PromiseConstructor);
|
|
29
|
-
/** The promise object for the defer */
|
|
30
|
-
promise: Promise<T>;
|
|
31
|
-
/** resolve the defered promise */
|
|
32
|
-
resolve: (result?: T) => void;
|
|
33
|
-
/** reject the deferred promise */
|
|
34
|
-
reject: (reason?: any) => void;
|
|
35
|
-
/**
|
|
36
|
-
* node.js callback for the deferred promise
|
|
37
|
-
*
|
|
38
|
-
* @param err - error
|
|
39
|
-
* @param args - result
|
|
40
|
-
* @returns nothing
|
|
41
|
-
*/
|
|
42
|
-
done: (err: Error, ...args: any[]) => void;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Create a promise Defer object
|
|
46
|
-
*
|
|
47
|
-
* Sample:
|
|
48
|
-
*
|
|
49
|
-
* ```js
|
|
50
|
-
* async function waitEvent() {
|
|
51
|
-
* const defer = xaa.makeDefer();
|
|
52
|
-
* someThing.on("event", (data) => defer.resolve(data))
|
|
53
|
-
* return defer.promise;
|
|
54
|
-
* }
|
|
55
|
-
* ```
|
|
56
|
-
*
|
|
57
|
-
* @param ThePromise - optional Promise constructor.
|
|
58
|
-
* @returns Defer instance
|
|
59
|
-
*/
|
|
60
|
-
export declare function makeDefer<T>(ThePromise?: PromiseConstructor): Defer<T>;
|
|
61
|
-
export { makeDefer as defer };
|
|
62
|
-
/**
|
|
63
|
-
* The error xaa.timeout will throw if operation timed out
|
|
64
|
-
*/
|
|
65
|
-
export declare class TimeoutError extends Error {
|
|
66
|
-
constructor(msg: string);
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* delay some milliseconds and then return `valOrFunc`
|
|
70
|
-
*
|
|
71
|
-
* Sample:
|
|
72
|
-
*
|
|
73
|
-
* ```js
|
|
74
|
-
* await xaa.delay(500);
|
|
75
|
-
* await xaa.delay(500, "Result");
|
|
76
|
-
* await xaa.delay(500, () => "Result");
|
|
77
|
-
* ```
|
|
78
|
-
*
|
|
79
|
-
* @param delayMs - number milliseconds to delay
|
|
80
|
-
* @param valOrFunc - the value to return. If it's a function, call it to get the value.
|
|
81
|
-
* It can be an async function.
|
|
82
|
-
* @returns `valOrFunc` or its returned value if it's a function.
|
|
83
|
-
*/
|
|
84
|
-
export declare function delay(delayMs: number): Promise<void>;
|
|
85
|
-
export declare function delay<T = void>(delayMs: number, valOrFunc: T): Promise<T>;
|
|
86
|
-
type Task<T> = Promise<T> | (() => Promise<T>);
|
|
87
|
-
type Tasks<T extends readonly any[]> = {
|
|
88
|
-
readonly [P in keyof T]: Task<T[P]>;
|
|
89
|
-
};
|
|
90
|
-
type Runnable<T> = T extends readonly any[] ? Tasks<T> : Task<T>;
|
|
91
|
-
type TimeoutRunnerOptions = {
|
|
92
|
-
TimeoutError: typeof TimeoutError;
|
|
93
|
-
Promise: PromiseConstructor;
|
|
94
|
-
};
|
|
95
|
-
/**
|
|
96
|
-
* TimeoutRunner for running tasks (promises) with a timeout
|
|
97
|
-
*
|
|
98
|
-
* Please use `xaa.timeout` or `xaa.runTimeout` APIs instead.
|
|
99
|
-
*/
|
|
100
|
-
export declare class TimeoutRunner<T> {
|
|
101
|
-
/**
|
|
102
|
-
* constructor
|
|
103
|
-
* @param maxMs - number of milliseconds to allow tasks to run
|
|
104
|
-
* @param rejectMsg - message to reject with when timeout triggers
|
|
105
|
-
* @param options - TimeoutRunnerOptions
|
|
106
|
-
*/
|
|
107
|
-
constructor(maxMs: number, rejectMsg: string, options: TimeoutRunnerOptions);
|
|
108
|
-
/**
|
|
109
|
-
* message to reject with when timeout triggers
|
|
110
|
-
*/
|
|
111
|
-
private defer;
|
|
112
|
-
/** setTimeout handle */
|
|
113
|
-
private timeout;
|
|
114
|
-
/**
|
|
115
|
-
* check if runner has failed with error
|
|
116
|
-
*
|
|
117
|
-
* @returns has error flag
|
|
118
|
-
*/
|
|
119
|
-
hasError(): boolean;
|
|
120
|
-
/**
|
|
121
|
-
* check if runner has finished with result
|
|
122
|
-
*
|
|
123
|
-
* @returns has result flag
|
|
124
|
-
*/
|
|
125
|
-
hasResult(): boolean;
|
|
126
|
-
/**
|
|
127
|
-
* Run tasks
|
|
128
|
-
*
|
|
129
|
-
* @param tasks - Promise or function that returns Promise, or array of them.
|
|
130
|
-
* @returns Promise to wait for tasks to complete, or timeout error.
|
|
131
|
-
*/
|
|
132
|
-
run<U extends Runnable<T>>(tasks: U): Promise<T | T[]>;
|
|
133
|
-
/**
|
|
134
|
-
* Cancel the operation and reject with msg
|
|
135
|
-
*
|
|
136
|
-
* @param msg - cancel message
|
|
137
|
-
*/
|
|
138
|
-
cancel(msg?: string): void;
|
|
139
|
-
/** Explicitly clear the setTimeout handle */
|
|
140
|
-
clear(): void;
|
|
141
|
-
/**
|
|
142
|
-
* Check if runner is done
|
|
143
|
-
*
|
|
144
|
-
* @returns is done flag
|
|
145
|
-
*/
|
|
146
|
-
isDone(): boolean;
|
|
147
|
-
/** number of milliseconds to allow tasks to run */
|
|
148
|
-
maxMs: number;
|
|
149
|
-
/** message to reject with if operation timed out */
|
|
150
|
-
rejectMsg: string;
|
|
151
|
-
/** the error if running failed */
|
|
152
|
-
error?: Error;
|
|
153
|
-
/** the result from running tasks */
|
|
154
|
-
result?: T | T[];
|
|
155
|
-
/** Promise constructor */
|
|
156
|
-
ThePromise: PromiseConstructor;
|
|
157
|
-
/** TimeoutError constructor */
|
|
158
|
-
TimeoutError: typeof TimeoutError;
|
|
159
|
-
}
|
|
160
|
-
/**
|
|
161
|
-
* Create a TimeoutRunner to run tasks (promises) with timeout
|
|
162
|
-
*
|
|
163
|
-
* Sample:
|
|
164
|
-
*
|
|
165
|
-
* ```js
|
|
166
|
-
* await xaa.timeout(1000, "timeout fetching data").run(() => fetch(url))
|
|
167
|
-
* ```
|
|
168
|
-
*
|
|
169
|
-
* with promises:
|
|
170
|
-
*
|
|
171
|
-
* ```js
|
|
172
|
-
* await xaa.timout(1000).run([promise1, promise2])
|
|
173
|
-
* ```
|
|
174
|
-
*
|
|
175
|
-
* @param maxMs - number of milliseconds to allow tasks to run
|
|
176
|
-
* @param rejectMsg - message to reject with when timeout triggers
|
|
177
|
-
* @returns TimeoutRunner object
|
|
178
|
-
*/
|
|
179
|
-
export declare function timeout<T>(maxMs: number, rejectMsg?: string, options?: TimeoutRunnerOptions): TimeoutRunner<T>;
|
|
180
|
-
/**
|
|
181
|
-
* Calls `timeout(maxMs, rejectMsg).run(tasks)`
|
|
182
|
-
*
|
|
183
|
-
* @param tasks - Promise or function or array of them
|
|
184
|
-
* @param maxMs - milliseconds to wait for the tasks to fulfill
|
|
185
|
-
* @param rejectMsg - message to reject with if operation timed out
|
|
186
|
-
* @returns promise results from all tasks
|
|
187
|
-
*/
|
|
188
|
-
export declare function runTimeout<T>(tasks: Task<T>, maxMs: number, rejectMsg?: string, options?: TimeoutRunnerOptions): Promise<T>;
|
|
189
|
-
export declare function runTimeout<T extends readonly any[]>(tasks: Tasks<T>, maxMs: number, rejectMsg?: string, options?: TimeoutRunnerOptions): Promise<T[]>;
|
|
190
|
-
/**
|
|
191
|
-
* The error xaa.map will throw if something went wrong.
|
|
192
|
-
*
|
|
193
|
-
* Contains a partial field for result mapped before error was encountered.
|
|
194
|
-
*/
|
|
195
|
-
export interface MapError<T> extends Error {
|
|
196
|
-
/** the result that has been mapped before error was encountered */
|
|
197
|
-
partial: T[];
|
|
198
|
-
}
|
|
199
|
-
/** options for xaa.map */
|
|
200
|
-
export type MapOptions = {
|
|
201
|
-
/** number of items to map concurrently */
|
|
202
|
-
concurrency: number;
|
|
203
|
-
/** the this passed to the map callback */
|
|
204
|
-
thisArg?: any;
|
|
205
|
-
};
|
|
206
|
-
/** context from xaa.map to the mapper callback */
|
|
207
|
-
export type MapContext<T> = {
|
|
208
|
-
/**
|
|
209
|
-
* indicate if another map operation during concurrent map has failed
|
|
210
|
-
* Mapping should observe this flag whenever possible and avoid continuing
|
|
211
|
-
* if it makes sense.
|
|
212
|
-
*/
|
|
213
|
-
failed?: boolean;
|
|
214
|
-
/**
|
|
215
|
-
* the original array that's passed to xaa.map
|
|
216
|
-
*/
|
|
217
|
-
array: readonly T[];
|
|
218
|
-
/**
|
|
219
|
-
* During concurrent map, if any mapper failed, this allow other inflight
|
|
220
|
-
* map functions to assert that no failure has occurred, else stop.
|
|
221
|
-
*/
|
|
222
|
-
assertNoFailure: () => void;
|
|
223
|
-
};
|
|
224
|
-
type Awaited<T> = T extends PromiseLike<infer T2> ? {
|
|
225
|
-
0: Awaited<T2>;
|
|
226
|
-
1: T2;
|
|
227
|
-
}[T2 extends PromiseLike<any> ? 0 : 1] : T;
|
|
228
|
-
/**
|
|
229
|
-
* callback function for xaa.map to map the value.
|
|
230
|
-
*
|
|
231
|
-
* @param value value to map
|
|
232
|
-
* @param index index of the value in the array
|
|
233
|
-
* @param context MapContext
|
|
234
|
-
* @returns any or a promise
|
|
235
|
-
*/
|
|
236
|
-
export type MapFunction<T, O> = (value: Awaited<T>, index: number, context: MapContext<T>) => O | Promise<O>;
|
|
237
|
-
export declare function mapSeries<T, O>(array: readonly T[], func?: MapFunction<T, O>, options?: MapOptions): Promise<O[]>;
|
|
238
|
-
/**
|
|
239
|
-
* async map array with concurrency
|
|
240
|
-
*
|
|
241
|
-
* - intended to be similar to `bluebird.map`
|
|
242
|
-
*
|
|
243
|
-
* @param array array to map, if any item is promise-like, it will be resolved first.
|
|
244
|
-
* @param func - callback to map values from the array
|
|
245
|
-
* @param options - MapOptions
|
|
246
|
-
* @returns promise with mapped result
|
|
247
|
-
*/
|
|
248
|
-
export declare function map<T, O>(array: readonly T[], func?: MapFunction<T, O>, options?: MapOptions): Promise<O[]>;
|
|
249
|
-
/**
|
|
250
|
-
* async version of array.forEach
|
|
251
|
-
* - iterate through array and await call func with each element and index
|
|
252
|
-
*
|
|
253
|
-
* Sample:
|
|
254
|
-
*
|
|
255
|
-
* ```js
|
|
256
|
-
* await xaa.each([1, 2, 3], async val => await xaa.delay(val))
|
|
257
|
-
* ```
|
|
258
|
-
*
|
|
259
|
-
* @param array array to each
|
|
260
|
-
* @param func callback for each
|
|
261
|
-
*/
|
|
262
|
-
export declare function each<T>(array: readonly T[], func: Consumer<T>): Promise<T[]>;
|
|
263
|
-
/**
|
|
264
|
-
* async filter array
|
|
265
|
-
*
|
|
266
|
-
* Sample:
|
|
267
|
-
*
|
|
268
|
-
* ```js
|
|
269
|
-
* await xaa.filter([1, 2, 3], async val => await validateResult(val))
|
|
270
|
-
* ```
|
|
271
|
-
*
|
|
272
|
-
* Beware: concurrency is fixed to 1.
|
|
273
|
-
*
|
|
274
|
-
* @param array array to filter
|
|
275
|
-
* @param func callback for filter
|
|
276
|
-
* @returns filtered result
|
|
277
|
-
*/
|
|
278
|
-
export declare function filter<T>(array: readonly T[], func: Predicate<T>): Promise<any[]>;
|
|
279
|
-
type ValueOrErrorHandler<T> = T extends Function ? never : T | Promise<T> | ((err?: Error) => T | Promise<T>);
|
|
280
|
-
/**
|
|
281
|
-
* try to:
|
|
282
|
-
* - await a promise
|
|
283
|
-
* - call and await function that returns a promise
|
|
284
|
-
*
|
|
285
|
-
* If exception occur, then return `valOrFunc`
|
|
286
|
-
*
|
|
287
|
-
* - if `valOrFunc` is a function, then return `valOrFunc(err)`
|
|
288
|
-
*
|
|
289
|
-
* @param funcOrPromise function or promise to try
|
|
290
|
-
* @param valOrFunc value, or callback to get value, to return if `func` throws
|
|
291
|
-
* @returns result, `valOrFunc`, or `valOrFunc(err)`.
|
|
292
|
-
*/
|
|
293
|
-
export declare function tryCatch<T, TAlt>(funcOrPromise: Producer<T>, valOrFunc?: ValueOrErrorHandler<TAlt>): Promise<T | TAlt>;
|
|
294
|
-
export { tryCatch as try };
|
|
295
|
-
/**
|
|
296
|
-
* Wrap the calling of a function into async/await (promise) context
|
|
297
|
-
* - intended to be similar to `bluebird.try`
|
|
298
|
-
*
|
|
299
|
-
* @param func function to wrap in async context
|
|
300
|
-
* @param args arguments to pass to `func`
|
|
301
|
-
* @returns result from `func`
|
|
302
|
-
*/
|
|
303
|
-
export declare function wrap<T, F extends (...args: any[]) => T>(func: F, ...args2: Parameters<F>): Promise<T>;
|
package/dist-esm/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,yFAAyF;AAEzF,OAAO,MAAM,MAAM,QAAQ,CAAC;AAO5B;;;;;GAKG;AACH,MAAM,UAAU,SAAS,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