@twin.org/core 0.9.3-next.5 → 0.9.3-next.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/dist/es/helpers/timeoutHelper.js +44 -0
- package/dist/es/helpers/timeoutHelper.js.map +1 -0
- package/dist/es/index.js +1 -0
- package/dist/es/index.js.map +1 -1
- package/dist/types/helpers/timeoutHelper.d.ts +21 -0
- package/dist/types/index.d.ts +1 -0
- package/docs/changelog.md +17 -0
- package/docs/reference/classes/TimeoutHelper.md +70 -0
- package/docs/reference/index.md +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// Copyright 2026 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
import { GeneralError } from "../errors/generalError.js";
|
|
4
|
+
import { Is } from "../utils/is.js";
|
|
5
|
+
/**
|
|
6
|
+
* Helper for bounding operations which can fail to settle.
|
|
7
|
+
*/
|
|
8
|
+
export class TimeoutHelper {
|
|
9
|
+
/**
|
|
10
|
+
* Reject an operation which has not settled within the given time.
|
|
11
|
+
* The operation itself cannot be cancelled, so a timed out operation is abandoned, which is
|
|
12
|
+
* the only option available when the identity wasm bindings panic instead of rejecting and
|
|
13
|
+
* leave the promise they returned pending forever.
|
|
14
|
+
* @param operation The operation to bound.
|
|
15
|
+
* @param timeoutMs The maximum time to wait in milliseconds, 0 or less waits indefinitely.
|
|
16
|
+
* @param source The source to use for the timeout error.
|
|
17
|
+
* @param message The message key to use for the timeout error.
|
|
18
|
+
* @param properties Additional properties to include in the timeout error.
|
|
19
|
+
* @returns The result of the operation.
|
|
20
|
+
* @throws GeneralError if the operation has not settled within timeoutMs.
|
|
21
|
+
*/
|
|
22
|
+
static async withTimeout(operation, timeoutMs, source, message, properties) {
|
|
23
|
+
if (timeoutMs <= 0) {
|
|
24
|
+
return operation;
|
|
25
|
+
}
|
|
26
|
+
let timer;
|
|
27
|
+
try {
|
|
28
|
+
return await Promise.race([
|
|
29
|
+
operation,
|
|
30
|
+
new Promise((resolve, reject) => {
|
|
31
|
+
timer = setTimeout(() => {
|
|
32
|
+
reject(new GeneralError(source, message, { ...properties, timeoutMs }));
|
|
33
|
+
}, timeoutMs);
|
|
34
|
+
})
|
|
35
|
+
]);
|
|
36
|
+
}
|
|
37
|
+
finally {
|
|
38
|
+
if (!Is.undefined(timer)) {
|
|
39
|
+
clearTimeout(timer);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=timeoutHelper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timeoutHelper.js","sourceRoot":"","sources":["../../../src/helpers/timeoutHelper.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAEpC;;GAEG;AACH,MAAM,OAAO,aAAa;IACzB;;;;;;;;;;;;OAYG;IACI,MAAM,CAAC,KAAK,CAAC,WAAW,CAC9B,SAAqB,EACrB,SAAiB,EACjB,MAAc,EACd,OAAe,EACf,UAAsC;QAEtC,IAAI,SAAS,IAAI,CAAC,EAAE,CAAC;YACpB,OAAO,SAAS,CAAC;QAClB,CAAC;QAED,IAAI,KAAgD,CAAC;QAErD,IAAI,CAAC;YACJ,OAAO,MAAM,OAAO,CAAC,IAAI,CAAC;gBACzB,SAAS;gBACT,IAAI,OAAO,CAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;oBACtC,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE;wBACvB,MAAM,CAAC,IAAI,YAAY,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE,GAAG,UAAU,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC;oBACzE,CAAC,EAAE,SAAS,CAAC,CAAC;gBACf,CAAC,CAAC;aACF,CAAC,CAAC;QACJ,CAAC;gBAAS,CAAC;YACV,IAAI,CAAC,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;gBAC1B,YAAY,CAAC,KAAK,CAAC,CAAC;YACrB,CAAC;QACF,CAAC;IACF,CAAC;CACD","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { GeneralError } from \"../errors/generalError.js\";\nimport { Is } from \"../utils/is.js\";\n\n/**\n * Helper for bounding operations which can fail to settle.\n */\nexport class TimeoutHelper {\n\t/**\n\t * Reject an operation which has not settled within the given time.\n\t * The operation itself cannot be cancelled, so a timed out operation is abandoned, which is\n\t * the only option available when the identity wasm bindings panic instead of rejecting and\n\t * leave the promise they returned pending forever.\n\t * @param operation The operation to bound.\n\t * @param timeoutMs The maximum time to wait in milliseconds, 0 or less waits indefinitely.\n\t * @param source The source to use for the timeout error.\n\t * @param message The message key to use for the timeout error.\n\t * @param properties Additional properties to include in the timeout error.\n\t * @returns The result of the operation.\n\t * @throws GeneralError if the operation has not settled within timeoutMs.\n\t */\n\tpublic static async withTimeout<T>(\n\t\toperation: Promise<T>,\n\t\ttimeoutMs: number,\n\t\tsource: string,\n\t\tmessage: string,\n\t\tproperties?: { [id: string]: unknown }\n\t): Promise<T> {\n\t\tif (timeoutMs <= 0) {\n\t\t\treturn operation;\n\t\t}\n\n\t\tlet timer: ReturnType<typeof setTimeout> | undefined;\n\n\t\ttry {\n\t\t\treturn await Promise.race([\n\t\t\t\toperation,\n\t\t\t\tnew Promise<never>((resolve, reject) => {\n\t\t\t\t\ttimer = setTimeout(() => {\n\t\t\t\t\t\treject(new GeneralError(source, message, { ...properties, timeoutMs }));\n\t\t\t\t\t}, timeoutMs);\n\t\t\t\t})\n\t\t\t]);\n\t\t} finally {\n\t\t\tif (!Is.undefined(timer)) {\n\t\t\t\tclearTimeout(timer);\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
|
package/dist/es/index.js
CHANGED
|
@@ -28,6 +28,7 @@ export * from "./helpers/numberHelper.js";
|
|
|
28
28
|
export * from "./helpers/objectHelper.js";
|
|
29
29
|
export * from "./helpers/randomHelper.js";
|
|
30
30
|
export * from "./helpers/stringHelper.js";
|
|
31
|
+
export * from "./helpers/timeoutHelper.js";
|
|
31
32
|
export * from "./helpers/uint8ArrayHelper.js";
|
|
32
33
|
export * from "./models/coerceType.js";
|
|
33
34
|
export * from "./models/IDuration.js";
|
package/dist/es/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC;AACxC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,uBAAuB,CAAC;AACtC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,0BAA0B,CAAC;AACzC,cAAc,wBAAwB,CAAC;AACvC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,iCAAiC,CAAC;AAChD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,iCAAiC,CAAC;AAChD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,wBAAwB,CAAC;AACvC,cAAc,0BAA0B,CAAC;AACzC,cAAc,wBAAwB,CAAC;AACvC,cAAc,0BAA0B,CAAC;AACzC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,wBAAwB,CAAC;AACvC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,qBAAqB,CAAC;AACpC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,0BAA0B,CAAC;AACzC,cAAc,iCAAiC,CAAC;AAChD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,wCAAwC,CAAC;AACvD,cAAc,8CAA8C,CAAC;AAC7D,cAAc,uBAAuB,CAAC;AACtC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,4CAA4C,CAAC;AAC3D,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,0BAA0B,CAAC;AACzC,cAAc,kCAAkC,CAAC;AACjD,cAAc,6CAA6C,CAAC;AAC5D,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AACvC,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nexport * from \"./encoding/base32.js\";\nexport * from \"./encoding/base58.js\";\nexport * from \"./encoding/base64.js\";\nexport * from \"./encoding/base64Url.js\";\nexport * from \"./errors/alreadyExistsError.js\";\nexport * from \"./errors/baseError.js\";\nexport * from \"./errors/conflictError.js\";\nexport * from \"./errors/generalError.js\";\nexport * from \"./errors/guardError.js\";\nexport * from \"./errors/notFoundError.js\";\nexport * from \"./errors/notImplementedError.js\";\nexport * from \"./errors/notSupportedError.js\";\nexport * from \"./errors/unauthorizedError.js\";\nexport * from \"./errors/unprocessableError.js\";\nexport * from \"./errors/validationError.js\";\nexport * from \"./factories/componentFactory.js\";\nexport * from \"./factories/facadeFactory.js\";\nexport * from \"./factories/factory.js\";\nexport * from \"./helpers/arrayHelper.js\";\nexport * from \"./helpers/envHelper.js\";\nexport * from \"./helpers/errorHelper.js\";\nexport * from \"./helpers/filenameHelper.js\";\nexport * from \"./helpers/hexHelper.js\";\nexport * from \"./helpers/jsonHelper.js\";\nexport * from \"./helpers/numberHelper.js\";\nexport * from \"./helpers/objectHelper.js\";\nexport * from \"./helpers/randomHelper.js\";\nexport * from \"./helpers/stringHelper.js\";\nexport * from \"./helpers/uint8ArrayHelper.js\";\nexport * from \"./models/coerceType.js\";\nexport * from \"./models/IDuration.js\";\nexport * from \"./models/compressionType.js\";\nexport * from \"./models/IComponent.js\";\nexport * from \"./models/IFacade.js\";\nexport * from \"./models/IError.js\";\nexport * from \"./models/II18nShared.js\";\nexport * from \"./models/IKeyValue.js\";\nexport * from \"./models/ILabelledValue.js\";\nexport * from \"./models/ILocale.js\";\nexport * from \"./models/ILocaleDictionary.js\";\nexport * from \"./models/ILocalesIndex.js\";\nexport * from \"./models/IMutexWaiter.js\";\nexport * from \"./models/IMutexWorkerMessage.js\";\nexport * from \"./models/IPatchOperation.js\";\nexport * from \"./models/ISharedObjectBufferOptions.js\";\nexport * from \"./models/ISharedObjectBufferWorkerMessage.js\";\nexport * from \"./models/IUrlParts.js\";\nexport * from \"./models/IValidationFailure.js\";\nexport * from \"./models/mutexMessageTypes.js\";\nexport * from \"./models/sharedObjectBufferMessageTypes.js\";\nexport * from \"./types/bitString.js\";\nexport * from \"./types/duration.js\";\nexport * from \"./types/durationRegExp.js\";\nexport * from \"./types/objectOrArray.js\";\nexport * from \"./types/singleOccurrenceArray.js\";\nexport * from \"./types/singleOccurrenceArrayDepthHelper.js\";\nexport * from \"./types/url.js\";\nexport * from \"./types/urn.js\";\nexport * from \"./utils/asyncCache.js\";\nexport * from \"./utils/lfuCache.js\";\nexport * from \"./utils/lruCache.js\";\nexport * from \"./utils/coerce.js\";\nexport * from \"./utils/compression.js\";\nexport * from \"./utils/converter.js\";\nexport * from \"./utils/guards.js\";\nexport * from \"./utils/i18n.js\";\nexport * from \"./utils/is.js\";\nexport * from \"./utils/mutex.js\";\nexport * from \"./utils/sharedObjectBuffer.js\";\nexport * from \"./utils/sharedStore.js\";\nexport * from \"./utils/validation.js\";\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC;AACxC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,uBAAuB,CAAC;AACtC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,0BAA0B,CAAC;AACzC,cAAc,wBAAwB,CAAC;AACvC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,iCAAiC,CAAC;AAChD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,iCAAiC,CAAC;AAChD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,wBAAwB,CAAC;AACvC,cAAc,0BAA0B,CAAC;AACzC,cAAc,wBAAwB,CAAC;AACvC,cAAc,0BAA0B,CAAC;AACzC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,wBAAwB,CAAC;AACvC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,qBAAqB,CAAC;AACpC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,0BAA0B,CAAC;AACzC,cAAc,iCAAiC,CAAC;AAChD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,wCAAwC,CAAC;AACvD,cAAc,8CAA8C,CAAC;AAC7D,cAAc,uBAAuB,CAAC;AACtC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,4CAA4C,CAAC;AAC3D,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,0BAA0B,CAAC;AACzC,cAAc,kCAAkC,CAAC;AACjD,cAAc,6CAA6C,CAAC;AAC5D,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AACvC,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nexport * from \"./encoding/base32.js\";\nexport * from \"./encoding/base58.js\";\nexport * from \"./encoding/base64.js\";\nexport * from \"./encoding/base64Url.js\";\nexport * from \"./errors/alreadyExistsError.js\";\nexport * from \"./errors/baseError.js\";\nexport * from \"./errors/conflictError.js\";\nexport * from \"./errors/generalError.js\";\nexport * from \"./errors/guardError.js\";\nexport * from \"./errors/notFoundError.js\";\nexport * from \"./errors/notImplementedError.js\";\nexport * from \"./errors/notSupportedError.js\";\nexport * from \"./errors/unauthorizedError.js\";\nexport * from \"./errors/unprocessableError.js\";\nexport * from \"./errors/validationError.js\";\nexport * from \"./factories/componentFactory.js\";\nexport * from \"./factories/facadeFactory.js\";\nexport * from \"./factories/factory.js\";\nexport * from \"./helpers/arrayHelper.js\";\nexport * from \"./helpers/envHelper.js\";\nexport * from \"./helpers/errorHelper.js\";\nexport * from \"./helpers/filenameHelper.js\";\nexport * from \"./helpers/hexHelper.js\";\nexport * from \"./helpers/jsonHelper.js\";\nexport * from \"./helpers/numberHelper.js\";\nexport * from \"./helpers/objectHelper.js\";\nexport * from \"./helpers/randomHelper.js\";\nexport * from \"./helpers/stringHelper.js\";\nexport * from \"./helpers/timeoutHelper.js\";\nexport * from \"./helpers/uint8ArrayHelper.js\";\nexport * from \"./models/coerceType.js\";\nexport * from \"./models/IDuration.js\";\nexport * from \"./models/compressionType.js\";\nexport * from \"./models/IComponent.js\";\nexport * from \"./models/IFacade.js\";\nexport * from \"./models/IError.js\";\nexport * from \"./models/II18nShared.js\";\nexport * from \"./models/IKeyValue.js\";\nexport * from \"./models/ILabelledValue.js\";\nexport * from \"./models/ILocale.js\";\nexport * from \"./models/ILocaleDictionary.js\";\nexport * from \"./models/ILocalesIndex.js\";\nexport * from \"./models/IMutexWaiter.js\";\nexport * from \"./models/IMutexWorkerMessage.js\";\nexport * from \"./models/IPatchOperation.js\";\nexport * from \"./models/ISharedObjectBufferOptions.js\";\nexport * from \"./models/ISharedObjectBufferWorkerMessage.js\";\nexport * from \"./models/IUrlParts.js\";\nexport * from \"./models/IValidationFailure.js\";\nexport * from \"./models/mutexMessageTypes.js\";\nexport * from \"./models/sharedObjectBufferMessageTypes.js\";\nexport * from \"./types/bitString.js\";\nexport * from \"./types/duration.js\";\nexport * from \"./types/durationRegExp.js\";\nexport * from \"./types/objectOrArray.js\";\nexport * from \"./types/singleOccurrenceArray.js\";\nexport * from \"./types/singleOccurrenceArrayDepthHelper.js\";\nexport * from \"./types/url.js\";\nexport * from \"./types/urn.js\";\nexport * from \"./utils/asyncCache.js\";\nexport * from \"./utils/lfuCache.js\";\nexport * from \"./utils/lruCache.js\";\nexport * from \"./utils/coerce.js\";\nexport * from \"./utils/compression.js\";\nexport * from \"./utils/converter.js\";\nexport * from \"./utils/guards.js\";\nexport * from \"./utils/i18n.js\";\nexport * from \"./utils/is.js\";\nexport * from \"./utils/mutex.js\";\nexport * from \"./utils/sharedObjectBuffer.js\";\nexport * from \"./utils/sharedStore.js\";\nexport * from \"./utils/validation.js\";\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helper for bounding operations which can fail to settle.
|
|
3
|
+
*/
|
|
4
|
+
export declare class TimeoutHelper {
|
|
5
|
+
/**
|
|
6
|
+
* Reject an operation which has not settled within the given time.
|
|
7
|
+
* The operation itself cannot be cancelled, so a timed out operation is abandoned, which is
|
|
8
|
+
* the only option available when the identity wasm bindings panic instead of rejecting and
|
|
9
|
+
* leave the promise they returned pending forever.
|
|
10
|
+
* @param operation The operation to bound.
|
|
11
|
+
* @param timeoutMs The maximum time to wait in milliseconds, 0 or less waits indefinitely.
|
|
12
|
+
* @param source The source to use for the timeout error.
|
|
13
|
+
* @param message The message key to use for the timeout error.
|
|
14
|
+
* @param properties Additional properties to include in the timeout error.
|
|
15
|
+
* @returns The result of the operation.
|
|
16
|
+
* @throws GeneralError if the operation has not settled within timeoutMs.
|
|
17
|
+
*/
|
|
18
|
+
static withTimeout<T>(operation: Promise<T>, timeoutMs: number, source: string, message: string, properties?: {
|
|
19
|
+
[id: string]: unknown;
|
|
20
|
+
}): Promise<T>;
|
|
21
|
+
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -26,6 +26,7 @@ export * from "./helpers/numberHelper.js";
|
|
|
26
26
|
export * from "./helpers/objectHelper.js";
|
|
27
27
|
export * from "./helpers/randomHelper.js";
|
|
28
28
|
export * from "./helpers/stringHelper.js";
|
|
29
|
+
export * from "./helpers/timeoutHelper.js";
|
|
29
30
|
export * from "./helpers/uint8ArrayHelper.js";
|
|
30
31
|
export * from "./models/coerceType.js";
|
|
31
32
|
export * from "./models/IDuration.js";
|
package/docs/changelog.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.9.3-next.6](https://github.com/iotaledger/twin-framework/compare/core-v0.9.3-next.5...core-v0.9.3-next.6) (2026-09-07)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* add TimeoutHelper ([2e0c50d](https://github.com/iotaledger/twin-framework/commit/2e0c50d70708f3a99e9e94ebad4b543250a1b987))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Dependencies
|
|
12
|
+
|
|
13
|
+
* The following workspace dependencies were updated
|
|
14
|
+
* dependencies
|
|
15
|
+
* @twin.org/nameof bumped from 0.9.3-next.5 to 0.9.3-next.6
|
|
16
|
+
* devDependencies
|
|
17
|
+
* @twin.org/nameof-transformer bumped from 0.9.3-next.5 to 0.9.3-next.6
|
|
18
|
+
* @twin.org/nameof-vitest-plugin bumped from 0.9.3-next.5 to 0.9.3-next.6
|
|
19
|
+
|
|
3
20
|
## [0.9.3-next.5](https://github.com/iotaledger/twin-framework/compare/core-v0.9.3-next.4...core-v0.9.3-next.5) (2026-09-04)
|
|
4
21
|
|
|
5
22
|
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# Class: TimeoutHelper
|
|
2
|
+
|
|
3
|
+
Helper for bounding operations which can fail to settle.
|
|
4
|
+
|
|
5
|
+
## Constructors
|
|
6
|
+
|
|
7
|
+
### Constructor
|
|
8
|
+
|
|
9
|
+
> **new TimeoutHelper**(): `TimeoutHelper`
|
|
10
|
+
|
|
11
|
+
#### Returns
|
|
12
|
+
|
|
13
|
+
`TimeoutHelper`
|
|
14
|
+
|
|
15
|
+
## Methods
|
|
16
|
+
|
|
17
|
+
### withTimeout() {#withtimeout}
|
|
18
|
+
|
|
19
|
+
> `static` **withTimeout**\<`T`\>(`operation`, `timeoutMs`, `source`, `message`, `properties?`): `Promise`\<`T`\>
|
|
20
|
+
|
|
21
|
+
Reject an operation which has not settled within the given time.
|
|
22
|
+
The operation itself cannot be cancelled, so a timed out operation is abandoned, which is
|
|
23
|
+
the only option available when the identity wasm bindings panic instead of rejecting and
|
|
24
|
+
leave the promise they returned pending forever.
|
|
25
|
+
|
|
26
|
+
#### Type Parameters
|
|
27
|
+
|
|
28
|
+
##### T
|
|
29
|
+
|
|
30
|
+
`T`
|
|
31
|
+
|
|
32
|
+
#### Parameters
|
|
33
|
+
|
|
34
|
+
##### operation
|
|
35
|
+
|
|
36
|
+
`Promise`\<`T`\>
|
|
37
|
+
|
|
38
|
+
The operation to bound.
|
|
39
|
+
|
|
40
|
+
##### timeoutMs
|
|
41
|
+
|
|
42
|
+
`number`
|
|
43
|
+
|
|
44
|
+
The maximum time to wait in milliseconds, 0 or less waits indefinitely.
|
|
45
|
+
|
|
46
|
+
##### source
|
|
47
|
+
|
|
48
|
+
`string`
|
|
49
|
+
|
|
50
|
+
The source to use for the timeout error.
|
|
51
|
+
|
|
52
|
+
##### message
|
|
53
|
+
|
|
54
|
+
`string`
|
|
55
|
+
|
|
56
|
+
The message key to use for the timeout error.
|
|
57
|
+
|
|
58
|
+
##### properties?
|
|
59
|
+
|
|
60
|
+
Additional properties to include in the timeout error.
|
|
61
|
+
|
|
62
|
+
#### Returns
|
|
63
|
+
|
|
64
|
+
`Promise`\<`T`\>
|
|
65
|
+
|
|
66
|
+
The result of the operation.
|
|
67
|
+
|
|
68
|
+
#### Throws
|
|
69
|
+
|
|
70
|
+
GeneralError if the operation has not settled within timeoutMs.
|
package/docs/reference/index.md
CHANGED
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
- [ObjectHelper](classes/ObjectHelper.md)
|
|
29
29
|
- [RandomHelper](classes/RandomHelper.md)
|
|
30
30
|
- [StringHelper](classes/StringHelper.md)
|
|
31
|
+
- [TimeoutHelper](classes/TimeoutHelper.md)
|
|
31
32
|
- [Uint8ArrayHelper](classes/Uint8ArrayHelper.md)
|
|
32
33
|
- [BitString](classes/BitString.md)
|
|
33
34
|
- [Duration](classes/Duration.md)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twin.org/core",
|
|
3
|
-
"version": "0.9.3-next.
|
|
3
|
+
"version": "0.9.3-next.6",
|
|
4
4
|
"description": "Helper methods/classes for data type checking/validation/guarding/error handling",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"node": ">=24.0.0"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@twin.org/nameof": "0.9.3-next.
|
|
17
|
+
"@twin.org/nameof": "0.9.3-next.6",
|
|
18
18
|
"intl-messageformat": "11.2.13",
|
|
19
19
|
"rfc6902": "5.3.0"
|
|
20
20
|
},
|