@minimaltech/node-infra 0.3.16 → 0.3.17
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/dist/utilities/index.js
CHANGED
@@ -19,6 +19,7 @@ __exportStar(require("./date.utility"), exports);
|
|
19
19
|
__exportStar(require("./error.utility"), exports);
|
20
20
|
__exportStar(require("./parse.utility"), exports);
|
21
21
|
__exportStar(require("./performance.utility"), exports);
|
22
|
+
__exportStar(require("./promise.utility"), exports);
|
22
23
|
__exportStar(require("./request.utility"), exports);
|
23
24
|
__exportStar(require("./url.utility"), exports);
|
24
25
|
//# sourceMappingURL=index.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utilities/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mDAAiC;AACjC,iDAA+B;AAC/B,kDAAgC;AAChC,kDAAgC;AAChC,wDAAsC;AACtC,oDAAkC;AAClC,gDAA8B"}
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utilities/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mDAAiC;AACjC,iDAA+B;AAC/B,kDAAgC;AAChC,kDAAgC;AAChC,wDAAsC;AACtC,oDAAkC;AAClC,oDAAkC;AAClC,gDAA8B"}
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import { ValueOrPromise } from '../common';
|
2
|
+
type TTask<T> = () => Promise<T>;
|
3
|
+
export declare const executePromiseWithLimit: <T>(opts: {
|
4
|
+
tasks: Array<TTask<T>>;
|
5
|
+
limit: number;
|
6
|
+
onTaskDone?: <R>(opts: {
|
7
|
+
result: R;
|
8
|
+
}) => ValueOrPromise<void>;
|
9
|
+
}) => Promise<Awaited<T>[]>;
|
10
|
+
export {};
|
@@ -0,0 +1,33 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
+
});
|
10
|
+
};
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
12
|
+
exports.executePromiseWithLimit = void 0;
|
13
|
+
const executePromiseWithLimit = (opts) => __awaiter(void 0, void 0, void 0, function* () {
|
14
|
+
const { tasks, limit, onTaskDone } = opts;
|
15
|
+
const results = [];
|
16
|
+
const executing = new Set();
|
17
|
+
for (const task of tasks) {
|
18
|
+
const promise = task().then(result => {
|
19
|
+
executing.delete(promise);
|
20
|
+
return result;
|
21
|
+
});
|
22
|
+
executing.add(promise);
|
23
|
+
results.push(promise);
|
24
|
+
if (executing.size >= limit) {
|
25
|
+
const done = yield Promise.race(executing);
|
26
|
+
onTaskDone === null || onTaskDone === void 0 ? void 0 : onTaskDone({ result: done });
|
27
|
+
}
|
28
|
+
}
|
29
|
+
yield Promise.all(executing);
|
30
|
+
return Promise.all(results);
|
31
|
+
});
|
32
|
+
exports.executePromiseWithLimit = executePromiseWithLimit;
|
33
|
+
//# sourceMappingURL=promise.utility.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"promise.utility.js","sourceRoot":"","sources":["../../src/utilities/promise.utility.ts"],"names":[],"mappings":";;;;;;;;;;;;AAIO,MAAM,uBAAuB,GAAG,CAAU,IAIhD,EAAE,EAAE;IACH,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,GAAG,IAAI,CAAC;IAE1C,MAAM,OAAO,GAAG,EAAE,CAAC;IACnB,MAAM,SAAS,GAAG,IAAI,GAAG,EAAE,CAAC;IAE5B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,OAAO,GAAG,IAAI,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE;YACnC,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YAC1B,OAAO,MAAM,CAAC;QAChB,CAAC,CAAC,CAAC;QAEH,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QACvB,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAEtB,IAAI,SAAS,CAAC,IAAI,IAAI,KAAK,EAAE,CAAC;YAC5B,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YAC3C,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAG,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;QACjC,CAAC;IACH,CAAC;IAED,MAAM,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IAC7B,OAAO,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;AAC9B,CAAC,CAAA,CAAC;AA3BW,QAAA,uBAAuB,2BA2BlC"}
|