@httptoolkit/util 0.1.1 → 0.1.2
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/promises.d.ts +8 -1
- package/dist/promises.js +6 -1
- package/dist/promises.js.map +1 -1
- package/package.json +1 -1
- package/src/promises.ts +15 -3
package/dist/promises.d.ts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
export type MaybePromise<T> = T | Promise<T>;
|
|
2
|
-
export declare const delay: (ms: number
|
|
2
|
+
export declare const delay: (ms: number, options?: {
|
|
3
|
+
/**
|
|
4
|
+
* If set, if the code is running in a compatible runtime (i.e. Node.js)
|
|
5
|
+
* then the .unref() will be used to ensure that this delay does not
|
|
6
|
+
* block the process shutdown.
|
|
7
|
+
*/
|
|
8
|
+
unref?: boolean;
|
|
9
|
+
}) => Promise<unknown>;
|
|
3
10
|
export declare function doWhile<T>(doFn: () => Promise<T>, whileFn: () => Promise<boolean> | boolean): Promise<void>;
|
|
4
11
|
export interface Deferred<T> {
|
|
5
12
|
resolve: (arg: T) => void;
|
package/dist/promises.js
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getDeferred = exports.doWhile = exports.delay = void 0;
|
|
4
|
-
const delay = (ms) => new Promise((resolve) =>
|
|
4
|
+
const delay = (ms, options = {}) => new Promise((resolve) => {
|
|
5
|
+
const timer = setTimeout(resolve, ms);
|
|
6
|
+
if (options.unref && timer.unref) {
|
|
7
|
+
timer.unref();
|
|
8
|
+
}
|
|
9
|
+
});
|
|
5
10
|
exports.delay = delay;
|
|
6
11
|
async function doWhile(doFn, whileFn) {
|
|
7
12
|
do {
|
package/dist/promises.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"promises.js","sourceRoot":"","sources":["../src/promises.ts"],"names":[],"mappings":";;;AAEO,MAAM,KAAK,GAAG,CAAC,EAAU,EAAE,EAAE,
|
|
1
|
+
{"version":3,"file":"promises.js","sourceRoot":"","sources":["../src/promises.ts"],"names":[],"mappings":";;;AAEO,MAAM,KAAK,GAAG,CAAC,EAAU,EAAE,UAO9B,EAAE,EAAE,EAAE,CACN,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;IACpB,MAAM,KAAK,GAAG,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;IAEtC,IAAI,OAAO,CAAC,KAAK,IAAK,KAAa,CAAC,KAAK,EAAE;QACtC,KAAa,CAAC,KAAK,EAAE,CAAC;KAC1B;AACL,CAAC,CAAC,CAAC;AAdM,QAAA,KAAK,SAcX;AAEA,KAAK,UAAU,OAAO,CACzB,IAAsB,EACtB,OAAyC;IAEzC,GAAG;QACC,MAAM,IAAI,EAAE,CAAC;KAChB,QAAQ,MAAM,OAAO,EAAE,EAAE;AAC9B,CAAC;AAPD,0BAOC;AAQD,SAAgB,WAAW;IACvB,IAAI,OAAO,GAAmC,SAAS,CAAC;IACxD,IAAI,MAAM,GAAsC,SAAS,CAAC;IAE1D,IAAI,OAAO,GAAG,IAAI,OAAO,CAAI,CAAC,SAAS,EAAE,QAAQ,EAAE,EAAE;QACjD,OAAO,GAAG,SAAS,CAAC;QACpB,MAAM,GAAG,QAAQ,CAAC;IACtB,CAAC,CAAC,CAAC;IAEH,oEAAoE;IACpE,iDAAiD;IACjD,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAS,CAAC;AAC/C,CAAC;AAZD,kCAYC"}
|
package/package.json
CHANGED
package/src/promises.ts
CHANGED
|
@@ -1,8 +1,20 @@
|
|
|
1
1
|
export type MaybePromise<T> = T | Promise<T>;
|
|
2
2
|
|
|
3
|
-
export const delay = (ms: number
|
|
4
|
-
|
|
5
|
-
)
|
|
3
|
+
export const delay = (ms: number, options: {
|
|
4
|
+
/**
|
|
5
|
+
* If set, if the code is running in a compatible runtime (i.e. Node.js)
|
|
6
|
+
* then the .unref() will be used to ensure that this delay does not
|
|
7
|
+
* block the process shutdown.
|
|
8
|
+
*/
|
|
9
|
+
unref?: boolean
|
|
10
|
+
} = {}) =>
|
|
11
|
+
new Promise((resolve) => {
|
|
12
|
+
const timer = setTimeout(resolve, ms);
|
|
13
|
+
|
|
14
|
+
if (options.unref && (timer as any).unref) {
|
|
15
|
+
(timer as any).unref();
|
|
16
|
+
}
|
|
17
|
+
});
|
|
6
18
|
|
|
7
19
|
export async function doWhile<T>(
|
|
8
20
|
doFn: () => Promise<T>,
|