ctx-core 5.7.0 → 5.8.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/all/promise_timeout/index.d.ts +1 -1
- package/all/promise_timeout/index.js +8 -3
- package/all/promise_timeout/index.test.ts +7 -0
- package/all/rmemo__wait/index.d.ts +1 -0
- package/all/rmemo__wait/index.js +4 -4
- package/all/rmemo__wait/index.test.ts +9 -0
- package/all/waitfor/index.d.ts +1 -1
- package/package.json +1 -1
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @param {Error}[error]
|
|
5
5
|
* @returns {Promise<unknown>}
|
|
6
6
|
*/
|
|
7
|
-
export
|
|
7
|
+
export function promise_timeout(
|
|
8
8
|
promise,
|
|
9
9
|
ms,
|
|
10
10
|
error
|
|
@@ -14,11 +14,16 @@ export async function promise_timeout(
|
|
|
14
14
|
let timeout = new Promise((_resolve, reject)=>{
|
|
15
15
|
id = setTimeout(()=>reject(error), ms)
|
|
16
16
|
})
|
|
17
|
-
|
|
17
|
+
let cancel_promise__resolve
|
|
18
|
+
let cancel_promise = new Promise(resolve=>cancel_promise__resolve = resolve)
|
|
19
|
+
let ret_promise = Promise.race([
|
|
18
20
|
typeof promise === 'function' ? promise() : promise,
|
|
19
|
-
timeout
|
|
21
|
+
timeout,
|
|
22
|
+
cancel_promise,
|
|
20
23
|
]).then(result=>{
|
|
21
24
|
clearTimeout(id)
|
|
22
25
|
return result
|
|
23
26
|
})
|
|
27
|
+
ret_promise.cancel = cancel_promise__resolve
|
|
28
|
+
return ret_promise
|
|
24
29
|
}
|
|
@@ -29,4 +29,11 @@ test('promise_timeout|timeout', async ()=>{
|
|
|
29
29
|
equal(count, 1)
|
|
30
30
|
equal(err?.message, 'Timeout 1ms')
|
|
31
31
|
})
|
|
32
|
+
test('promise_timeout|cancel|arg', async ()=>{
|
|
33
|
+
const promise = promise_timeout(
|
|
34
|
+
new Promise<number>(()=>{}),
|
|
35
|
+
1000)
|
|
36
|
+
promise.cancel(5)
|
|
37
|
+
equal(await promise, 5)
|
|
38
|
+
})
|
|
32
39
|
test.run()
|
package/all/rmemo__wait/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/// <reference types="../rmemo/index.d.ts" />
|
|
2
2
|
/// <reference types="./index.d.ts" />
|
|
3
|
-
import { isNumber_ } from '../isNumber/index.js'
|
|
4
3
|
import { promise_timeout } from '../promise_timeout/index.js'
|
|
5
4
|
import { memo_ } from '../rmemo/index.js'
|
|
6
5
|
/**
|
|
@@ -26,9 +25,10 @@ export function rmemo__wait(
|
|
|
26
25
|
memo()
|
|
27
26
|
})
|
|
28
27
|
let promise =
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
promise_timeout(
|
|
29
|
+
_subscribe_wait,
|
|
30
|
+
timeout ?? Infinity,
|
|
31
|
+
error)
|
|
32
32
|
// prevent GC
|
|
33
33
|
promise.m = memo
|
|
34
34
|
return promise
|
|
@@ -15,4 +15,13 @@ test('rmemo__wait', async ()=>{
|
|
|
15
15
|
await promise
|
|
16
16
|
equal(subject$(), 1)
|
|
17
17
|
})
|
|
18
|
+
test('rmemo__wait|cancel', async ()=>{
|
|
19
|
+
const subject$ = sig_(-1)
|
|
20
|
+
const promise = rmemo__wait(
|
|
21
|
+
subject$,
|
|
22
|
+
subject=>subject >= 0,
|
|
23
|
+
10_000)
|
|
24
|
+
promise.cancel(500)
|
|
25
|
+
equal(await promise, 500)
|
|
26
|
+
})
|
|
18
27
|
test.run()
|
package/all/waitfor/index.d.ts
CHANGED