@ton/appkit 1.0.0-alpha.1 → 1.0.0-alpha.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/.turbo/turbo-build.log +4 -16
- package/CHANGELOG.md +11 -0
- package/dist/cjs/utils/index.d.ts +1 -1
- package/dist/cjs/utils/index.d.ts.map +1 -1
- package/dist/cjs/utils/index.js +1 -1
- package/dist/{esm/utils/promise/cancel-promise.test.d.ts → cjs/utils/promise/with-timeout.d.ts} +2 -2
- package/dist/cjs/utils/promise/with-timeout.d.ts.map +1 -0
- package/dist/cjs/utils/promise/with-timeout.js +13 -0
- package/dist/esm/utils/index.d.ts +1 -1
- package/dist/esm/utils/index.d.ts.map +1 -1
- package/dist/esm/utils/index.js +1 -1
- package/dist/{cjs/utils/promise/cancel-promise.test.d.ts → esm/utils/promise/with-timeout.d.ts} +2 -2
- package/dist/esm/utils/promise/with-timeout.d.ts.map +1 -0
- package/dist/{cjs/utils/promise/cancel-promise.d.ts → esm/utils/promise/with-timeout.js} +2 -2
- package/package.json +9 -8
- package/src/utils/index.ts +1 -1
- package/{dist/esm/utils/promise/cancel-promise.d.ts → src/utils/promise/with-timeout.ts} +3 -2
- package/dist/cjs/utils/promise/cancel-promise.d.ts.map +0 -1
- package/dist/cjs/utils/promise/cancel-promise.js +0 -19
- package/dist/cjs/utils/promise/cancel-promise.test.d.ts.map +0 -1
- package/dist/cjs/utils/promise/cancel-promise.test.js +0 -25
- package/dist/esm/utils/promise/cancel-promise.d.ts.map +0 -1
- package/dist/esm/utils/promise/cancel-promise.js +0 -15
- package/dist/esm/utils/promise/cancel-promise.test.d.ts.map +0 -1
- package/dist/esm/utils/promise/cancel-promise.test.js +0 -23
- package/src/utils/promise/cancel-promise.test.ts +0 -28
- package/src/utils/promise/cancel-promise.ts +0 -16
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,16 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
> @ton/appkit@1.0.0-alpha.1 build:clean /home/runner/work/kit/kit/packages/appkit
|
|
7
|
-
> git clean -xdf dist
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
> @ton/appkit@1.0.0-alpha.1 build:cjs /home/runner/work/kit/kit/packages/appkit
|
|
11
|
-
> tsc -p tsconfig.cjs.json
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
> @ton/appkit@1.0.0-alpha.1 build:esm /home/runner/work/kit/kit/packages/appkit
|
|
15
|
-
> tsc -p tsconfig.json
|
|
16
|
-
|
|
1
|
+
$ pnpm build:clean && pnpm build:cjs && pnpm build:esm
|
|
2
|
+
$ git clean -xdf dist
|
|
3
|
+
$ tsc -p tsconfig.cjs.json
|
|
4
|
+
$ tsc -p tsconfig.json
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# @ton/appkit
|
|
2
2
|
|
|
3
|
+
## 1.0.0-alpha.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- c1f0edf: - Added confirmation modals for the swap and staking widgets.
|
|
8
|
+
- Improved error handling across swap and staking flows, especially when the network is unavailable — failures now surface in the submit button instead of hanging.
|
|
9
|
+
- Moved `cancelPromise` from `@ton/appkit` to `@ton/walletkit` and renamed it to `withTimeout` to reflect what it actually does (it does not abort the underlying operation). `@ton/appkit` re-exports it.
|
|
10
|
+
- Updated dependencies [c1f0edf]
|
|
11
|
+
- Updated dependencies [864636c]
|
|
12
|
+
- @ton/walletkit@1.0.0-alpha.2
|
|
13
|
+
|
|
3
14
|
## 1.0.0-alpha.1
|
|
4
15
|
|
|
5
16
|
### Patch Changes
|
|
@@ -25,7 +25,7 @@ export * from './nft/nft-info';
|
|
|
25
25
|
export * from './object/map-values';
|
|
26
26
|
export * from './predicate/is-number';
|
|
27
27
|
export * from './predicate/is-string';
|
|
28
|
-
export * from './promise/
|
|
28
|
+
export * from './promise/with-timeout';
|
|
29
29
|
export * from './promise/sleep';
|
|
30
30
|
export * from './query/filter-query-options';
|
|
31
31
|
export * from './network/resolve-network';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEzE,cAAc,4BAA4B,CAAC;AAC3C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,oCAAoC,CAAC;AACnD,cAAc,0BAA0B,CAAC;AACzC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,kCAAkC,CAAC;AACjD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,iBAAiB,CAAC;AAChC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEzE,cAAc,4BAA4B,CAAC;AAC3C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,oCAAoC,CAAC;AACnD,cAAc,0BAA0B,CAAC;AACzC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,kCAAkC,CAAC;AACjD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,iBAAiB,CAAC;AAChC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,iBAAiB,CAAC;AAChC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,0BAA0B,CAAC"}
|
package/dist/cjs/utils/index.js
CHANGED
|
@@ -45,7 +45,7 @@ __exportStar(require("./nft/nft-info"), exports);
|
|
|
45
45
|
__exportStar(require("./object/map-values"), exports);
|
|
46
46
|
__exportStar(require("./predicate/is-number"), exports);
|
|
47
47
|
__exportStar(require("./predicate/is-string"), exports);
|
|
48
|
-
__exportStar(require("./promise/
|
|
48
|
+
__exportStar(require("./promise/with-timeout"), exports);
|
|
49
49
|
__exportStar(require("./promise/sleep"), exports);
|
|
50
50
|
__exportStar(require("./query/filter-query-options"), exports);
|
|
51
51
|
__exportStar(require("./network/resolve-network"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"with-timeout.d.ts","sourceRoot":"","sources":["../../../../src/utils/promise/with-timeout.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) TonTech.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.withTimeout = void 0;
|
|
11
|
+
// Re-exported from walletkit so the kit packages share a single source of truth.
|
|
12
|
+
var walletkit_1 = require("@ton/walletkit");
|
|
13
|
+
Object.defineProperty(exports, "withTimeout", { enumerable: true, get: function () { return walletkit_1.withTimeout; } });
|
|
@@ -25,7 +25,7 @@ export * from './nft/nft-info';
|
|
|
25
25
|
export * from './object/map-values';
|
|
26
26
|
export * from './predicate/is-number';
|
|
27
27
|
export * from './predicate/is-string';
|
|
28
|
-
export * from './promise/
|
|
28
|
+
export * from './promise/with-timeout';
|
|
29
29
|
export * from './promise/sleep';
|
|
30
30
|
export * from './query/filter-query-options';
|
|
31
31
|
export * from './network/resolve-network';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEzE,cAAc,4BAA4B,CAAC;AAC3C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,oCAAoC,CAAC;AACnD,cAAc,0BAA0B,CAAC;AACzC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,kCAAkC,CAAC;AACjD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,iBAAiB,CAAC;AAChC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEzE,cAAc,4BAA4B,CAAC;AAC3C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,oCAAoC,CAAC;AACnD,cAAc,0BAA0B,CAAC;AACzC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,kCAAkC,CAAC;AACjD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,iBAAiB,CAAC;AAChC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,iBAAiB,CAAC;AAChC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,0BAA0B,CAAC"}
|
package/dist/esm/utils/index.js
CHANGED
|
@@ -25,7 +25,7 @@ export * from './nft/nft-info';
|
|
|
25
25
|
export * from './object/map-values';
|
|
26
26
|
export * from './predicate/is-number';
|
|
27
27
|
export * from './predicate/is-string';
|
|
28
|
-
export * from './promise/
|
|
28
|
+
export * from './promise/with-timeout';
|
|
29
29
|
export * from './promise/sleep';
|
|
30
30
|
export * from './query/filter-query-options';
|
|
31
31
|
export * from './network/resolve-network';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"with-timeout.d.ts","sourceRoot":"","sources":["../../../../src/utils/promise/with-timeout.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
// Re-exported from walletkit so the kit packages share a single source of truth.
|
|
9
|
+
export { withTimeout } from '@ton/walletkit';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ton/appkit",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -79,14 +79,15 @@
|
|
|
79
79
|
}
|
|
80
80
|
},
|
|
81
81
|
"dependencies": {
|
|
82
|
-
"lru-cache": "11.
|
|
83
|
-
"@ton/walletkit": "1.0.0-alpha.
|
|
82
|
+
"lru-cache": "^11.5.0",
|
|
83
|
+
"@ton/walletkit": "1.0.0-alpha.2"
|
|
84
84
|
},
|
|
85
85
|
"peerDependencies": {
|
|
86
86
|
"@tanstack/query-core": ">=5.0.0",
|
|
87
87
|
"@ton/core": "^0.62.0 || ^0.63.0",
|
|
88
88
|
"@ton/crypto": "^3.3.0",
|
|
89
|
-
"@tonconnect/ui": ">=2.
|
|
89
|
+
"@tonconnect/ui": ">=2.5.0-alpha.1",
|
|
90
|
+
"@tonconnect/sdk": ">=3.5.0-alpha.1"
|
|
90
91
|
},
|
|
91
92
|
"peerDependenciesMeta": {
|
|
92
93
|
"@tonconnect/ui": {
|
|
@@ -103,10 +104,10 @@
|
|
|
103
104
|
"author": "",
|
|
104
105
|
"license": "ISC",
|
|
105
106
|
"devDependencies": {
|
|
106
|
-
"@tanstack/query-core": "5.
|
|
107
|
-
"@ton/core": "0.63.1",
|
|
108
|
-
"@tonconnect/ui": "2.5.0-alpha.0",
|
|
109
|
-
"typescript": "
|
|
107
|
+
"@tanstack/query-core": "^5.100.14",
|
|
108
|
+
"@ton/core": "^0.63.1",
|
|
109
|
+
"@tonconnect/ui": "^2.5.0-alpha.0",
|
|
110
|
+
"typescript": "5.9.3",
|
|
110
111
|
"vitest": "^4.1.4"
|
|
111
112
|
},
|
|
112
113
|
"scripts": {
|
package/src/utils/index.ts
CHANGED
|
@@ -27,7 +27,7 @@ export * from './nft/nft-info';
|
|
|
27
27
|
export * from './object/map-values';
|
|
28
28
|
export * from './predicate/is-number';
|
|
29
29
|
export * from './predicate/is-string';
|
|
30
|
-
export * from './promise/
|
|
30
|
+
export * from './promise/with-timeout';
|
|
31
31
|
export * from './promise/sleep';
|
|
32
32
|
export * from './query/filter-query-options';
|
|
33
33
|
export * from './network/resolve-network';
|
|
@@ -5,5 +5,6 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
|
|
9
|
+
// Re-exported from walletkit so the kit packages share a single source of truth.
|
|
10
|
+
export { withTimeout } from '@ton/walletkit';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cancel-promise.d.ts","sourceRoot":"","sources":["../../../../src/utils/promise/cancel-promise.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,eAAO,MAAM,aAAa,GAAI,CAAC,EAAE,SAAS,CAAC,EAAE,WAAW,MAAM,KAAG,OAAO,CAAC,CAAC,CAOzE,CAAC"}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Copyright (c) TonTech.
|
|
4
|
-
*
|
|
5
|
-
* This source code is licensed under the MIT license found in the
|
|
6
|
-
* LICENSE file in the root directory of this source tree.
|
|
7
|
-
*
|
|
8
|
-
*/
|
|
9
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.cancelPromise = void 0;
|
|
11
|
-
const cancelPromise = (promise, timeoutMs) => {
|
|
12
|
-
return Promise.race([
|
|
13
|
-
promise,
|
|
14
|
-
new Promise((_, reject) => {
|
|
15
|
-
setTimeout(() => reject(new Error(`Execution timed out - ${timeoutMs}ms`)), timeoutMs);
|
|
16
|
-
}),
|
|
17
|
-
]);
|
|
18
|
-
};
|
|
19
|
-
exports.cancelPromise = cancelPromise;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cancel-promise.test.d.ts","sourceRoot":"","sources":["../../../../src/utils/promise/cancel-promise.test.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Copyright (c) TonTech.
|
|
4
|
-
*
|
|
5
|
-
* This source code is licensed under the MIT license found in the
|
|
6
|
-
* LICENSE file in the root directory of this source tree.
|
|
7
|
-
*
|
|
8
|
-
*/
|
|
9
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
const vitest_1 = require("vitest");
|
|
11
|
-
const cancel_promise_1 = require("./cancel-promise");
|
|
12
|
-
(0, vitest_1.describe)('cancelPromise', () => {
|
|
13
|
-
(0, vitest_1.it)('should resolve if promise resolves before timeout', async () => {
|
|
14
|
-
const promise = new Promise((resolve) => setTimeout(() => resolve('success'), 10));
|
|
15
|
-
await (0, vitest_1.expect)((0, cancel_promise_1.cancelPromise)(promise, 50)).resolves.toBe('success');
|
|
16
|
-
});
|
|
17
|
-
(0, vitest_1.it)('should reject if promise times out', async () => {
|
|
18
|
-
const promise = new Promise((resolve) => setTimeout(() => resolve('success'), 50));
|
|
19
|
-
await (0, vitest_1.expect)((0, cancel_promise_1.cancelPromise)(promise, 10)).rejects.toThrow('Execution timed out - 10ms');
|
|
20
|
-
});
|
|
21
|
-
(0, vitest_1.it)('should propagate rejection from original promise', async () => {
|
|
22
|
-
const promise = new Promise((_, reject) => setTimeout(() => reject(new Error('failure')), 10));
|
|
23
|
-
await (0, vitest_1.expect)((0, cancel_promise_1.cancelPromise)(promise, 50)).rejects.toThrow('failure');
|
|
24
|
-
});
|
|
25
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cancel-promise.d.ts","sourceRoot":"","sources":["../../../../src/utils/promise/cancel-promise.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,eAAO,MAAM,aAAa,GAAI,CAAC,EAAE,SAAS,CAAC,EAAE,WAAW,MAAM,KAAG,OAAO,CAAC,CAAC,CAOzE,CAAC"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) TonTech.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*
|
|
7
|
-
*/
|
|
8
|
-
export const cancelPromise = (promise, timeoutMs) => {
|
|
9
|
-
return Promise.race([
|
|
10
|
-
promise,
|
|
11
|
-
new Promise((_, reject) => {
|
|
12
|
-
setTimeout(() => reject(new Error(`Execution timed out - ${timeoutMs}ms`)), timeoutMs);
|
|
13
|
-
}),
|
|
14
|
-
]);
|
|
15
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cancel-promise.test.d.ts","sourceRoot":"","sources":["../../../../src/utils/promise/cancel-promise.test.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) TonTech.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*
|
|
7
|
-
*/
|
|
8
|
-
import { describe, expect, it } from 'vitest';
|
|
9
|
-
import { cancelPromise } from './cancel-promise';
|
|
10
|
-
describe('cancelPromise', () => {
|
|
11
|
-
it('should resolve if promise resolves before timeout', async () => {
|
|
12
|
-
const promise = new Promise((resolve) => setTimeout(() => resolve('success'), 10));
|
|
13
|
-
await expect(cancelPromise(promise, 50)).resolves.toBe('success');
|
|
14
|
-
});
|
|
15
|
-
it('should reject if promise times out', async () => {
|
|
16
|
-
const promise = new Promise((resolve) => setTimeout(() => resolve('success'), 50));
|
|
17
|
-
await expect(cancelPromise(promise, 10)).rejects.toThrow('Execution timed out - 10ms');
|
|
18
|
-
});
|
|
19
|
-
it('should propagate rejection from original promise', async () => {
|
|
20
|
-
const promise = new Promise((_, reject) => setTimeout(() => reject(new Error('failure')), 10));
|
|
21
|
-
await expect(cancelPromise(promise, 50)).rejects.toThrow('failure');
|
|
22
|
-
});
|
|
23
|
-
});
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) TonTech.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import { describe, expect, it } from 'vitest';
|
|
10
|
-
|
|
11
|
-
import { cancelPromise } from './cancel-promise';
|
|
12
|
-
|
|
13
|
-
describe('cancelPromise', () => {
|
|
14
|
-
it('should resolve if promise resolves before timeout', async () => {
|
|
15
|
-
const promise = new Promise((resolve) => setTimeout(() => resolve('success'), 10));
|
|
16
|
-
await expect(cancelPromise(promise, 50)).resolves.toBe('success');
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it('should reject if promise times out', async () => {
|
|
20
|
-
const promise = new Promise((resolve) => setTimeout(() => resolve('success'), 50));
|
|
21
|
-
await expect(cancelPromise(promise, 10)).rejects.toThrow('Execution timed out - 10ms');
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it('should propagate rejection from original promise', async () => {
|
|
25
|
-
const promise = new Promise((_, reject) => setTimeout(() => reject(new Error('failure')), 10));
|
|
26
|
-
await expect(cancelPromise(promise, 50)).rejects.toThrow('failure');
|
|
27
|
-
});
|
|
28
|
-
});
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) TonTech.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
export const cancelPromise = <T>(promise: T, timeoutMs: number): Promise<T> => {
|
|
10
|
-
return Promise.race([
|
|
11
|
-
promise,
|
|
12
|
-
new Promise((_, reject) => {
|
|
13
|
-
setTimeout(() => reject(new Error(`Execution timed out - ${timeoutMs}ms`)), timeoutMs);
|
|
14
|
-
}) as T,
|
|
15
|
-
]);
|
|
16
|
-
};
|