@@ -20,37 +20,16 @@ const c = new LRUCache<number, number, void>({
2020 } ,
2121} )
2222
23- // c.set(1, 10)
24- // c.set(2, 20)
25-
26- // make them stale
27- // clock.advance(2000)
28-
29- //t.ok(c.getRemainingTTL(1) < 0, {
30- // found: c.getRemainingTTL(1),
31- // wanted: '< 0',
32- //})
33- //t.ok(c.getRemainingTTL(2) < 0, {
34- // found: c.getRemainingTTL(2),
35- // wanted: '< 0',
36- //})
37-
3823const ac = new AbortController ( )
39- const ac2 = new AbortController ( )
40- // fails
24+
4125const p2 = c . fetch ( 2 , { signal : ac . signal } )
4226const p1 = c . fetch ( 1 , { signal : ac . signal } )
4327
44- //c.set(3, 3)
45-
46- // works
47- // const p1 = c.fetch(1, { signal: ac.signal })
48- // const p2 = c.fetch(2, { signal: ac.signal })
49-
5028clock . advance ( 50 )
5129await new Promise < void > ( res => queueMicrotask ( res ) )
30+
5231ac . abort ( new Error ( 'gimme the stale value' ) )
53- ac2 . abort ( new Error ( 'gimme the stale value 2' ) )
32+
5433t . equal ( await p1 , undefined )
5534t . equal ( await p2 , undefined )
5635
@@ -59,10 +38,12 @@ t.equal(c.get(2, { allowStale: true }), undefined, 'get expect undef 2')
5938
6039clock . advance ( 100 )
6140await new Promise < void > ( res => queueMicrotask ( res ) ) . then ( ( ) => { } )
41+
6242t . equal ( c . get ( 1 ) , 1 , 'get expect 1' )
6343t . equal ( c . get ( 2 ) , undefined , 'get 2 expect undef' )
6444
6545clock . advance ( 100 )
6646await new Promise < void > ( res => queueMicrotask ( res ) ) . then ( ( ) => { } )
47+
6748t . equal ( c . get ( 1 ) , 1 , 'get expect 1' )
6849t . equal ( c . get ( 2 ) , 2 , 'get expect 2' )
0 commit comments