@sha1n/about-time 0.2.0 → 0.2.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/dist/lib/eventually.js +11 -8
- package/lib/eventually.ts +11 -8
- package/package.json +23 -12
package/dist/lib/eventually.js
CHANGED
|
@@ -16,25 +16,28 @@ async function until(condition, options) {
|
|
|
16
16
|
const deadline = (options === null || options === void 0 ? void 0 : options.deadline) ? Date.now() + (0, toMilliseconds_1.toMilliseconds)(options.deadline, options.units) : Number.MAX_VALUE;
|
|
17
17
|
const interval = (options === null || options === void 0 ? void 0 : options.interval) ? (0, toMilliseconds_1.toMilliseconds)(options.interval, options.units) : defaultInterval;
|
|
18
18
|
return new Promise((resolve, reject) => {
|
|
19
|
-
|
|
19
|
+
let handle;
|
|
20
|
+
const poll = () => {
|
|
20
21
|
if (Date.now() > deadline) {
|
|
21
|
-
clearInterval(handle);
|
|
22
22
|
reject(new types_1.TimeoutError());
|
|
23
|
+
return;
|
|
23
24
|
}
|
|
24
25
|
try {
|
|
25
26
|
if (condition()) {
|
|
26
|
-
clearInterval(handle);
|
|
27
27
|
resolve();
|
|
28
28
|
}
|
|
29
|
+
else {
|
|
30
|
+
handle = setTimeout(poll, interval);
|
|
31
|
+
if (options === null || options === void 0 ? void 0 : options.unref) {
|
|
32
|
+
handle.unref();
|
|
33
|
+
}
|
|
34
|
+
}
|
|
29
35
|
}
|
|
30
36
|
catch (e) {
|
|
31
|
-
clearInterval(handle);
|
|
32
37
|
reject(e);
|
|
33
38
|
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
handle.unref();
|
|
37
|
-
}
|
|
39
|
+
};
|
|
40
|
+
poll();
|
|
38
41
|
});
|
|
39
42
|
}
|
|
40
43
|
/**
|
package/lib/eventually.ts
CHANGED
|
@@ -14,26 +14,29 @@ async function until(condition: () => boolean, options?: PollOptions): Promise<v
|
|
|
14
14
|
const interval = options?.interval ? toMilliseconds(options.interval, options.units) : defaultInterval;
|
|
15
15
|
|
|
16
16
|
return new Promise<void>((resolve, reject) => {
|
|
17
|
-
|
|
17
|
+
let handle: NodeJS.Timeout;
|
|
18
|
+
|
|
19
|
+
const poll = () => {
|
|
18
20
|
if (Date.now() > deadline) {
|
|
19
|
-
clearInterval(handle);
|
|
20
21
|
reject(new TimeoutError());
|
|
22
|
+
return;
|
|
21
23
|
}
|
|
22
24
|
|
|
23
25
|
try {
|
|
24
26
|
if (condition()) {
|
|
25
|
-
clearInterval(handle);
|
|
26
27
|
resolve();
|
|
28
|
+
} else {
|
|
29
|
+
handle = setTimeout(poll, interval);
|
|
30
|
+
if (options?.unref) {
|
|
31
|
+
handle.unref();
|
|
32
|
+
}
|
|
27
33
|
}
|
|
28
34
|
} catch (e) {
|
|
29
|
-
clearInterval(handle);
|
|
30
35
|
reject(e);
|
|
31
36
|
}
|
|
32
|
-
}
|
|
37
|
+
};
|
|
33
38
|
|
|
34
|
-
|
|
35
|
-
handle.unref();
|
|
36
|
-
}
|
|
39
|
+
poll();
|
|
37
40
|
});
|
|
38
41
|
}
|
|
39
42
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sha1n/about-time",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"description": "A set of essential time related utilities",
|
|
6
6
|
"repository": "https://github.com/sha1n/about-time",
|
|
@@ -29,13 +29,17 @@
|
|
|
29
29
|
"build": "tsc",
|
|
30
30
|
"lint": "eslint --fix --ext .js,.ts .",
|
|
31
31
|
"jest": "DEBUG='error:*' jest --coverage",
|
|
32
|
-
"test": "
|
|
33
|
-
"prepare": "
|
|
32
|
+
"test": "pnpm jest && pnpm lint",
|
|
33
|
+
"prepare": "pnpm run build"
|
|
34
|
+
},
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public",
|
|
37
|
+
"registry": "https://registry.npmjs.org/"
|
|
34
38
|
},
|
|
35
39
|
"devDependencies": {
|
|
36
40
|
"@types/chance": "^1.1.3",
|
|
37
41
|
"@types/is-ci": "^3.0.0",
|
|
38
|
-
"@types/jest": "^
|
|
42
|
+
"@types/jest": "^29.5.14",
|
|
39
43
|
"@types/node": "^22.0.0",
|
|
40
44
|
"@typescript-eslint/eslint-plugin": "^8.0.0",
|
|
41
45
|
"@typescript-eslint/parser": "^8.0.0",
|
|
@@ -43,28 +47,35 @@
|
|
|
43
47
|
"eslint": "^8.57.0",
|
|
44
48
|
"eslint-config-prettier": "^8.5.0",
|
|
45
49
|
"eslint-plugin-import": "^2.26.0",
|
|
46
|
-
"eslint-plugin-jest": "^
|
|
50
|
+
"eslint-plugin-jest": "^29.12.1",
|
|
47
51
|
"eslint-plugin-no-floating-promise": "^1.0.2",
|
|
48
52
|
"eslint-plugin-node": "^11.1.0",
|
|
49
53
|
"eslint-plugin-prettier": "^4.0.0",
|
|
50
|
-
"eslint-plugin-unused-imports": "^
|
|
54
|
+
"eslint-plugin-unused-imports": "^4.3.0",
|
|
51
55
|
"is-ci": "^3.0.1",
|
|
52
|
-
"jest": "^
|
|
53
|
-
"jest-environment-node": "^
|
|
54
|
-
"jest-extended": "^
|
|
56
|
+
"jest": "^29.7.0",
|
|
57
|
+
"jest-environment-node": "^29.7.0",
|
|
58
|
+
"jest-extended": "^7.0.0",
|
|
55
59
|
"jest-html-reporters": "^3.0.6",
|
|
56
|
-
"jest-mock-extended": "^
|
|
60
|
+
"jest-mock-extended": "^4.0.0",
|
|
57
61
|
"jest-summary-reporter": "^0.0.2",
|
|
58
62
|
"prettier": "^2.6.2",
|
|
59
|
-
"ts-jest": "^
|
|
63
|
+
"ts-jest": "^29.4.6",
|
|
60
64
|
"ts-node": "^10.9.2",
|
|
61
65
|
"typescript": "^5.5.0"
|
|
62
66
|
},
|
|
63
|
-
"packageManager": "
|
|
67
|
+
"packageManager": "pnpm@9.15.4",
|
|
64
68
|
"dependencies": {
|
|
65
69
|
"@typescript-eslint/typescript-estree": "^8.0.0"
|
|
66
70
|
},
|
|
67
71
|
"engines": {
|
|
68
72
|
"node": ">=24"
|
|
73
|
+
},
|
|
74
|
+
"resolutions": {
|
|
75
|
+
"json5": "^2.2.3",
|
|
76
|
+
"socks": "^2.8.3"
|
|
77
|
+
},
|
|
78
|
+
"pnpm": {
|
|
79
|
+
"nodeLinker": "node-modules"
|
|
69
80
|
}
|
|
70
81
|
}
|