ctx-core 5.4.0 → 5.4.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.
@@ -1,8 +1,11 @@
1
- import type { rmemo_T, rmemo_val_T } from '../rmemo/index.js'
1
+ import type { memo_T, rmemo_T, rmemo_val_T } from '../rmemo/index.js'
2
2
  export declare function rmemo__wait<
3
3
  _rmemo_T extends rmemo_T<unknown> = rmemo_T<unknown>
4
4
  >(
5
5
  memo:_rmemo_T,
6
6
  condition_fn:(val:rmemo_val_T<_rmemo_T>)=>unknown,
7
7
  timeout?:number
8
- ):Promise<rmemo_val_T<_rmemo_T>>
8
+ ):Promise<rmemo_val_T<_rmemo_T>>&{
9
+ // prevent early usGC
10
+ m:memo_T<unknown>
11
+ }
@@ -10,12 +10,20 @@ import { memo_ } from '../rmemo/index.js'
10
10
  * @returns {Promise<*>|Promise<unknown>}
11
11
  */
12
12
  export function rmemo__wait(rmemo, condition_fn, timeout) {
13
+ let memo
13
14
  const _subscribe_wait = new Promise(resolve=>{
14
- memo_(()=>{
15
+ memo = memo_(()=>{
15
16
  if (condition_fn(rmemo())) {
16
17
  resolve(rmemo())
17
18
  }
18
- })()
19
+ })
20
+ memo()
19
21
  })
20
- return isNumber_(timeout) ? promise_timeout(_subscribe_wait, timeout) : _subscribe_wait
22
+ let promise =
23
+ isNumber_(timeout)
24
+ ? promise_timeout(_subscribe_wait, timeout)
25
+ : _subscribe_wait
26
+ // prevent GC
27
+ promise.m = memo
28
+ return promise
21
29
  }
@@ -3,21 +3,16 @@ import { equal } from 'uvu/assert'
3
3
  import { sig_ } from '../rmemo/index.js'
4
4
  import { rmemo__wait } from './index.js'
5
5
  test('rmemo__wait', async ()=>{
6
- const subject = await new Promise(resolve=>{
7
- let subject = -1
8
- const subject$ = sig_(subject)
9
- rmemo__wait(subject$, $=>$ >= 0, 10_000).then(_subject=>{
10
- subject = _subject
11
- equal(_subject, 1)
12
- equal(subject, 1)
13
- resolve(_subject)
14
- return _subject
15
- })
16
- equal(subject, -1)
17
- subject$._ = 1
18
- equal(subject, -1)
19
- equal(subject$(), 1)
20
- })
21
- equal(subject, 1)
6
+ const subject$ = sig_(-1)
7
+ const promise = rmemo__wait(
8
+ subject$,
9
+ subject=>subject >= 0,
10
+ 10_000)
11
+ equal(promise.m.memor, [])
12
+ equal(subject$(), -1)
13
+ subject$._ = 1
14
+ equal(subject$(), 1)
15
+ await promise
16
+ equal(subject$(), 1)
22
17
  })
23
18
  test.run()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ctx-core",
3
- "version": "5.4.0",
3
+ "version": "5.4.1",
4
4
  "description": "ctx-core core library",
5
5
  "keywords": [
6
6
  "ctx-core",