File tree Expand file tree Collapse file tree 7 files changed +153
-0
lines changed Expand file tree Collapse file tree 7 files changed +153
-0
lines changed Original file line number Diff line number Diff line change
1
+ import audit from "../src/audit.js" ;
2
+ import throttle from "../src/throttle.js" ;
3
+ import sample from "../src/sample.js" ;
4
+ import debounce from "../src/debounce.js" ;
5
+ import sleep from "../src/sleep.js" ;
6
+ import whenDomLoaded from "../src/when-dom-loaded.js" ;
7
+ import whenLoaded from "../src/when-loaded.js" ;
8
+
9
+ const main = async ( ) => {
10
+ // audit
11
+ {
12
+ const fn = ( ) => { } ;
13
+ const auditedFn = audit ( fn , 20 ) ;
14
+
15
+ auditedFn ( 1 ) ;
16
+ auditedFn ( 2 ) ;
17
+ }
18
+
19
+ // throttle
20
+ {
21
+ const fn = ( ) => { } ;
22
+ const throttledFn = throttle ( fn , 20 ) ;
23
+
24
+ throttledFn ( 1 ) ;
25
+ throttledFn ( 2 ) ;
26
+ }
27
+
28
+ // sample
29
+ {
30
+ const fn = ( ) => { } ;
31
+ const sampledFn = sample ( fn , 20 ) ;
32
+
33
+ sampledFn ( 1 ) ;
34
+ sampledFn ( 2 ) ;
35
+ }
36
+
37
+ // debounce
38
+ {
39
+ const fn = ( ) => { } ;
40
+ const debouncedFn = debounce ( fn , 20 ) ;
41
+
42
+ debouncedFn ( 1 ) ;
43
+ debouncedFn ( 2 ) ;
44
+ }
45
+
46
+ // sleep
47
+ {
48
+ await sleep ( 20 ) ;
49
+ await sleep ( new Date ( Date . now ( ) + 20 ) ) ;
50
+ }
51
+
52
+ // whenDomLoaded
53
+ {
54
+ const fn = ( ) => { } ;
55
+ whenDomLoaded ( fn ) ;
56
+ }
57
+
58
+ // whenLoaded
59
+ {
60
+ const fn = ( ) => { } ;
61
+ whenLoaded ( fn ) ;
62
+ }
63
+ } ;
64
+
65
+ main ( ) ;
Original file line number Diff line number Diff line change
1
+ import { frameQueue } from '../src/FrameQueue.js' ;
2
+
3
+ const main = async ( ) => {
4
+ frameQueue . pause ( ) ;
5
+ const task = frameQueue . enqueue ( ( ) => { } ) ;
6
+ frameQueue . resume ( ) ;
7
+ frameQueue . dequeue ( task ) ;
8
+ if ( ! frameQueue . isEmpty ) frameQueue . clear ( ) ;
9
+ } ;
10
+
11
+ main ( ) ;
Original file line number Diff line number Diff line change
1
+ import { idleQueue } from '../src/IdleQueue.js' ;
2
+
3
+ const main = async ( ) => {
4
+ idleQueue . pause ( ) ;
5
+ const task = idleQueue . enqueue ( ( ) => { } ) ;
6
+ idleQueue . resume ( ) ;
7
+ idleQueue . dequeue ( task ) ;
8
+ if ( ! idleQueue . isEmpty ) idleQueue . clear ( ) ;
9
+ } ;
10
+
11
+ main ( ) ;
Original file line number Diff line number Diff line change
1
+ import { pageWatcher } from '../src/PageWatcher.js' ;
2
+
3
+ const main = async ( ) => {
4
+ pageWatcher . pause ( ) ;
5
+ const task = pageWatcher . enqueue ( ( ) => { } ) ;
6
+ pageWatcher . resume ( ) ;
7
+ pageWatcher . dequeue ( task ) ;
8
+ if ( ! pageWatcher . isEmpty ) pageWatcher . clear ( ) ;
9
+ } ;
10
+
11
+ main ( ) ;
Original file line number Diff line number Diff line change
1
+ import Retainer from '../src/Retainer.js' ;
2
+
3
+ const main = async ( ) => {
4
+ const retainer = new Retainer ( {
5
+ create : ( ) => Promise . resolve ( 1 ) ,
6
+ destroy : ( ) => Promise . resolve ( ) ,
7
+ retentionPeriod : 1_000 ,
8
+ } ) ;
9
+
10
+ const value1 = await retainer . get ( ) ;
11
+ void value1 ;
12
+ await retainer . release ( ) ;
13
+
14
+ const value2 = await retainer . get ( ) ;
15
+ void value2 ;
16
+ await retainer . release ( true ) ;
17
+ } ;
18
+
19
+ main ( ) ;
Original file line number Diff line number Diff line change
1
+ import { scheduler , repeat } from '../src/Scheduler.js' ;
2
+
3
+ const main = async ( ) => {
4
+ scheduler . pause ( ) ;
5
+ const task = scheduler . enqueue ( ( ) => { } , 10 ) ;
6
+ scheduler . resume ( ) ;
7
+ scheduler . dequeue ( task ) ;
8
+ if ( ! scheduler . isEmpty ) scheduler . clear ( ) ;
9
+
10
+ scheduler . enqueue ( repeat ( ( ) => { } , 10 ) , 50 ) ;
11
+
12
+ await scheduler . schedule ( 100 ) ;
13
+ } ;
14
+
15
+ main ( ) ;
Original file line number Diff line number Diff line change
1
+ import Throttler from '../src/Throttler.js' ;
2
+ import sleep from '../src/sleep.js' ;
3
+
4
+ const main = async ( ) => {
5
+ const throttler = new Throttler ( ) ;
6
+
7
+ await throttler . wait ( 'a' ) ;
8
+ await throttler . wait ( 'b' ) ;
9
+ await throttler . wait ( 'a' ) ;
10
+
11
+ if ( throttler . isVacuuming ) throttler . stopVacuum ( ) ;
12
+ throttler . startVacuum ( ) ;
13
+
14
+ const lastSeen = throttler . getLastSeen ( 'a' ) ;
15
+ void lastSeen ;
16
+
17
+ const delay = throttler . getDelay ( 'a' ) ;
18
+ await sleep ( delay ) ;
19
+ } ;
20
+
21
+ main ( ) ;
You can’t perform that action at this time.
0 commit comments