@xapp/arachne-utils 0.8.4 → 0.8.6

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/lib/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  /*! Copyright (c) 2020, XAPP AI */
2
2
  export * from "./ArachneURLPattern";
3
3
  export * from "./normalizeURL";
4
+ export * from "./promiseWithTimeout";
package/lib/index.js CHANGED
@@ -17,4 +17,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  __exportStar(require("./ArachneURLPattern"), exports);
19
19
  __exportStar(require("./normalizeURL"), exports);
20
+ __exportStar(require("./promiseWithTimeout"), exports);
20
21
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,kCAAkC;;;;;;;;;;;;;;;;AAElC,sDAAoC;AACpC,iDAA+B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,kCAAkC;;;;;;;;;;;;;;;;AAElC,sDAAoC;AACpC,iDAA+B;AAC/B,uDAAqC"}
@@ -0,0 +1,12 @@
1
+ /*! Copyright (c) 2020, XAPP AI */
2
+ export declare class TimeoutError extends Error {
3
+ readonly name = "TimeoutError";
4
+ }
5
+ /**
6
+ * Wraps the function that returns a promise with a timeout
7
+ *
8
+ * @param timeoutMs
9
+ * @param promise
10
+ * @param failureMessage
11
+ */
12
+ export declare const promiseWithTimeout: <T>(timeoutMs: number, promise: () => Promise<T>, failureMessage?: string | Error) => Promise<T>;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ /*! Copyright (c) 2020, XAPP AI */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.promiseWithTimeout = exports.TimeoutError = void 0;
5
+ class TimeoutError extends Error {
6
+ constructor() {
7
+ super(...arguments);
8
+ this.name = "TimeoutError";
9
+ }
10
+ }
11
+ exports.TimeoutError = TimeoutError;
12
+ /**
13
+ * Wraps the function that returns a promise with a timeout
14
+ *
15
+ * @param timeoutMs
16
+ * @param promise
17
+ * @param failureMessage
18
+ */
19
+ const promiseWithTimeout = (timeoutMs, promise, failureMessage) => {
20
+ let timeoutHandle;
21
+ let error;
22
+ if (!failureMessage) {
23
+ error = new TimeoutError();
24
+ }
25
+ else if (typeof failureMessage === "string") {
26
+ error = new TimeoutError(failureMessage);
27
+ }
28
+ else {
29
+ error = failureMessage;
30
+ }
31
+ const timeoutPromise = new Promise((accept, reject) => {
32
+ timeoutHandle = setTimeout(() => reject(error), timeoutMs);
33
+ });
34
+ return Promise.race([
35
+ promise(),
36
+ timeoutPromise,
37
+ ]).then((result) => {
38
+ clearTimeout(timeoutHandle);
39
+ return result;
40
+ });
41
+ };
42
+ exports.promiseWithTimeout = promiseWithTimeout;
43
+ //# sourceMappingURL=promiseWithTimeout.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"promiseWithTimeout.js","sourceRoot":"","sources":["../src/promiseWithTimeout.ts"],"names":[],"mappings":";AAAA,kCAAkC;;;AAElC,MAAa,YAAa,SAAQ,KAAK;IAAvC;;QACa,SAAI,GAAG,cAAc,CAAC;IACnC,CAAC;CAAA;AAFD,oCAEC;AAED;;;;;;GAMG;AACI,MAAM,kBAAkB,GAAG,CAAI,SAAiB,EAAE,OAAyB,EAAE,cAA+B,EAAc,EAAE;IAC/H,IAAI,aAA6B,CAAC;IAElC,IAAI,KAAY,CAAC;IAEjB,IAAI,CAAC,cAAc,EAAE;QACjB,KAAK,GAAG,IAAI,YAAY,EAAE,CAAC;KAC9B;SAAM,IAAI,OAAO,cAAc,KAAK,QAAQ,EAAE;QAC3C,KAAK,GAAG,IAAI,YAAY,CAAC,cAAc,CAAC,CAAA;KAC3C;SAAM;QACH,KAAK,GAAG,cAAc,CAAC;KAC1B;IAED,MAAM,cAAc,GAAG,IAAI,OAAO,CAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE;QACzD,aAAa,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,SAAS,CAAC,CAAA;IAC9D,CAAC,CAAC,CAAC;IAEH,OAAO,OAAO,CAAC,IAAI,CAAC;QAChB,OAAO,EAAE;QACT,cAAc;KACjB,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE;QACf,YAAY,CAAC,aAAa,CAAC,CAAC;QAC5B,OAAO,MAAM,CAAC;IAClB,CAAC,CAAC,CAAC;AACP,CAAC,CAAA;AAxBY,QAAA,kBAAkB,sBAwB9B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xapp/arachne-utils",
3
- "version": "0.8.4",
3
+ "version": "0.8.6",
4
4
  "types": "lib/index",
5
5
  "main": "lib/index",
6
6
  "files": [
@@ -14,10 +14,10 @@
14
14
  "node": "^14 || ^16 || ^18"
15
15
  },
16
16
  "devDependencies": {
17
- "@microsoft/api-extractor": "7.36.3",
17
+ "@microsoft/api-extractor": "7.36.4",
18
18
  "@types/chai": "4.3.5",
19
19
  "@types/mocha": "10.0.1",
20
- "@types/node": "18.17.3",
20
+ "@types/node": "18.17.4",
21
21
  "@types/sinon": "10.0.16",
22
22
  "@types/sinon-chai": "3.2.9",
23
23
  "@xapp/config": "0.2.3",
@@ -38,5 +38,5 @@
38
38
  "clean": "rm -rf ./lib/*",
39
39
  "test": "mocha --recursive -r ts-node/register \"./src/**/*.test.ts\""
40
40
  },
41
- "gitHead": "c7eac0dd4977046df5c19709a203d32cd7a5bc29"
41
+ "gitHead": "54475f52151753a01136f8d2bfa2294afbf11d7c"
42
42
  }