homebridge-plugin-utils 1.4.0 → 1.5.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/dist/utils.d.ts +2 -1
- package/dist/utils.js +9 -4
- package/dist/utils.js.map +1 -1
- package/package.json +3 -3
package/dist/utils.d.ts
CHANGED
|
@@ -27,5 +27,6 @@ export interface HomebridgePluginLogging {
|
|
|
27
27
|
info: (message: string, ...parameters: unknown[]) => void;
|
|
28
28
|
warn: (message: string, ...parameters: unknown[]) => void;
|
|
29
29
|
}
|
|
30
|
-
export declare function sleep(sleepTimer: number): Promise<NodeJS.Timeout>;
|
|
31
30
|
export declare function retry(operation: () => Promise<boolean>, retryInterval: number, totalRetries?: number): Promise<boolean>;
|
|
31
|
+
export declare function runWithTimeout<T>(promise: Promise<T>, timeout: number): Promise<T | null>;
|
|
32
|
+
export declare function sleep(sleepTimer: number): Promise<NodeJS.Timeout>;
|
package/dist/utils.js
CHANGED
|
@@ -2,10 +2,6 @@
|
|
|
2
2
|
*
|
|
3
3
|
* utils.ts: Useful utility functions when writing TypeScript.
|
|
4
4
|
*/
|
|
5
|
-
// Emulate a sleep function.
|
|
6
|
-
export async function sleep(sleepTimer) {
|
|
7
|
-
return new Promise(resolve => setTimeout(resolve, sleepTimer));
|
|
8
|
-
}
|
|
9
5
|
// Retry an operation until we're successful.
|
|
10
6
|
export async function retry(operation, retryInterval, totalRetries) {
|
|
11
7
|
if ((totalRetries !== undefined) && (totalRetries < 0)) {
|
|
@@ -20,4 +16,13 @@ export async function retry(operation, retryInterval, totalRetries) {
|
|
|
20
16
|
// We were successful - we're done.
|
|
21
17
|
return true;
|
|
22
18
|
}
|
|
19
|
+
// Run a promise with a guaranteed timeout to complete.
|
|
20
|
+
export async function runWithTimeout(promise, timeout) {
|
|
21
|
+
const timeoutPromise = new Promise((resolve) => setTimeout(() => resolve(null), timeout));
|
|
22
|
+
return Promise.race([promise, timeoutPromise]);
|
|
23
|
+
}
|
|
24
|
+
// Emulate a sleep function.
|
|
25
|
+
export async function sleep(sleepTimer) {
|
|
26
|
+
return new Promise(resolve => setTimeout(resolve, sleepTimer));
|
|
27
|
+
}
|
|
23
28
|
//# sourceMappingURL=utils.js.map
|
package/dist/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AA4CH,
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AA4CH,6CAA6C;AAC7C,MAAM,CAAC,KAAK,UAAU,KAAK,CAAC,SAAiC,EAAE,aAAqB,EAAE,YAAqB;IAEzG,IAAG,CAAC,YAAY,KAAK,SAAS,CAAC,IAAI,CAAC,YAAY,GAAG,CAAC,CAAC,EAAE,CAAC;QAEtD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,wCAAwC;IACxC,IAAG,CAAC,CAAC,MAAM,SAAS,EAAE,CAAC,EAAE,CAAC;QAExB,4FAA4F;QAC5F,MAAM,KAAK,CAAC,aAAa,CAAC,CAAC;QAE3B,OAAO,KAAK,CAAC,SAAS,EAAE,aAAa,EAAE,CAAC,YAAY,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,YAAY,EAAE,CAAC,CAAC;IACpG,CAAC;IAED,mCAAmC;IACnC,OAAO,IAAI,CAAC;AACd,CAAC;AAED,uDAAuD;AACvD,MAAM,CAAC,KAAK,UAAU,cAAc,CAAI,OAAmB,EAAE,OAAe;IAE1E,MAAM,cAAc,GAAG,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC;IAEhG,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC,CAAC;AACjD,CAAC;AAED,4BAA4B;AAC5B,MAAM,CAAC,KAAK,UAAU,KAAK,CAAC,UAAkB;IAE5C,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC,CAAC;AACjE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "homebridge-plugin-utils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"displayName": "Homebridge Plugin Utilities",
|
|
5
5
|
"description": "Opinionated utilities to provide common capabilities and create rich configuration webUI experiences for Homebridge plugins.",
|
|
6
6
|
"author": {
|
|
@@ -39,12 +39,12 @@
|
|
|
39
39
|
},
|
|
40
40
|
"main": "dist/index.js",
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@stylistic/eslint-plugin": "2.
|
|
42
|
+
"@stylistic/eslint-plugin": "2.2.0",
|
|
43
43
|
"@types/node": "20.14.2",
|
|
44
44
|
"eslint": "8.57.0",
|
|
45
45
|
"shx": "^0.3.4",
|
|
46
46
|
"typescript": "5.4.5",
|
|
47
|
-
"typescript-eslint": "^7.
|
|
47
|
+
"typescript-eslint": "^7.13.0"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
50
|
"mqtt": "^5.7.0"
|