@@ -45,6 +45,28 @@ function parseArgs() {
45
45
46
46
let UUID = 0 ;
47
47
48
+ let beginCount = 0 ;
49
+ let endCount = 0 ;
50
+ let beginEventCount = 0 ;
51
+ let endEventCount = 0 ;
52
+ let runCount = 0 ;
53
+ let joinCount = 0 ;
54
+ let deferCount = 0 ;
55
+ let scheduleCount = 0 ;
56
+ let scheduleIterableCount = 0 ;
57
+ let deferOnceCount = 0 ;
58
+ let scheduleOnceCount = 0 ;
59
+ let setTimeoutCount = 0 ;
60
+ let laterCount = 0 ;
61
+ let throttleCount = 0 ;
62
+ let debounceCount = 0 ;
63
+ let cancelTimersCount = 0 ;
64
+ let cancelCount = 0 ;
65
+ let autorunsCreatedCount = 0 ;
66
+ let autorunsCompletedCount = 0 ;
67
+ let deferredActionQueuesCreatedCount = 0 ;
68
+ let nestedDeferredActionQueuesCreated = 0 ;
69
+
48
70
export default class Backburner {
49
71
public static Queue = Queue ;
50
72
@@ -54,6 +76,38 @@ export default class Backburner {
54
76
55
77
public options : any ;
56
78
79
+ public get counters ( ) {
80
+ return {
81
+ begin : beginCount ,
82
+ end : endCount ,
83
+ events : {
84
+ begin : beginEventCount ,
85
+ end : endEventCount ,
86
+ } ,
87
+ autoruns : {
88
+ created : autorunsCreatedCount ,
89
+ completed : autorunsCompletedCount ,
90
+ } ,
91
+ run : runCount ,
92
+ join : joinCount ,
93
+ defer : deferCount ,
94
+ schedule : scheduleCount ,
95
+ scheduleIterable : scheduleIterableCount ,
96
+ deferOnce : deferOnceCount ,
97
+ scheduleOnce : scheduleOnceCount ,
98
+ setTimeout : setTimeoutCount ,
99
+ later : laterCount ,
100
+ throttle : throttleCount ,
101
+ debounce : debounceCount ,
102
+ cancelTimers : cancelTimersCount ,
103
+ cancel : cancelCount ,
104
+ loops : {
105
+ total : deferredActionQueuesCreatedCount ,
106
+ nested : nestedDeferredActionQueuesCreated ,
107
+ } ,
108
+ } ;
109
+ }
110
+
57
111
private _onBegin : ( currentInstance : DeferredActionQueues , previousInstance : DeferredActionQueues | null ) => void ;
58
112
private _onEnd : ( currentInstance : DeferredActionQueues , nextInstance : DeferredActionQueues | null ) => void ;
59
113
private queueNames : string [ ] ;
@@ -109,6 +163,7 @@ export default class Backburner {
109
163
} ;
110
164
111
165
this . _boundAutorunEnd = ( ) => {
166
+ autorunsCompletedCount ++ ;
112
167
this . _autorun = null ;
113
168
this . end ( ) ;
114
169
} ;
@@ -119,6 +174,7 @@ export default class Backburner {
119
174
@return instantiated class DeferredActionQueues
120
175
*/
121
176
public begin ( ) : DeferredActionQueues {
177
+ beginCount ++ ;
122
178
let options = this . options ;
123
179
let previousInstance = this . currentInstance ;
124
180
let current ;
@@ -128,9 +184,12 @@ export default class Backburner {
128
184
this . _cancelAutorun ( ) ;
129
185
} else {
130
186
if ( previousInstance !== null ) {
187
+ nestedDeferredActionQueuesCreated ++ ;
131
188
this . instanceStack . push ( previousInstance ) ;
132
189
}
190
+ deferredActionQueuesCreatedCount ++ ;
133
191
current = this . currentInstance = new DeferredActionQueues ( this . queueNames , options ) ;
192
+ beginEventCount ++ ;
134
193
this . _trigger ( 'begin' , current , previousInstance ) ;
135
194
}
136
195
@@ -140,6 +199,7 @@ export default class Backburner {
140
199
}
141
200
142
201
public end ( ) {
202
+ endCount ++ ;
143
203
let currentInstance = this . currentInstance ;
144
204
let nextInstance : DeferredActionQueues | null = null ;
145
205
@@ -158,6 +218,7 @@ export default class Backburner {
158
218
finallyAlreadyCalled = true ;
159
219
160
220
if ( result === QUEUE_STATE . Pause ) {
221
+ autorunsCreatedCount ++ ;
161
222
const next = this . _platform . next ;
162
223
this . _autorun = next ( this . _boundAutorunEnd ) ;
163
224
} else {
@@ -167,6 +228,7 @@ export default class Backburner {
167
228
nextInstance = this . instanceStack . pop ( ) as DeferredActionQueues ;
168
229
this . currentInstance = nextInstance ;
169
230
}
231
+ endEventCount ++ ;
170
232
this . _trigger ( 'end' , currentInstance , nextInstance ) ;
171
233
this . _onEnd ( currentInstance , nextInstance ) ;
172
234
}
@@ -210,6 +272,7 @@ export default class Backburner {
210
272
public run ( target : Function | any | null , method ?: Function | string , ...args ) ;
211
273
public run ( target : any | null | undefined , method ?: Function , ...args : any [ ] ) ;
212
274
public run ( ) {
275
+ runCount ++ ;
213
276
let [ target , method , args ] = parseArgs ( ...arguments ) ;
214
277
return this . _run ( target , method , args ) ;
215
278
}
@@ -232,6 +295,7 @@ export default class Backburner {
232
295
public join ( target : Function | any | null , method ?: Function | string , ...args ) ;
233
296
public join ( target : any | null | undefined , method ?: Function , ...args : any [ ] ) ;
234
297
public join ( ) {
298
+ joinCount ++ ;
235
299
let [ target , method , args ] = parseArgs ( ...arguments ) ;
236
300
return this . _join ( target , method , args ) ;
237
301
}
@@ -240,6 +304,7 @@ export default class Backburner {
240
304
* @deprecated please use schedule instead.
241
305
*/
242
306
public defer ( queueName , targetOrMethod , ..._args ) {
307
+ deferCount ++ ;
243
308
return this . schedule ( queueName , targetOrMethod , ..._args ) ;
244
309
}
245
310
@@ -250,6 +315,7 @@ export default class Backburner {
250
315
public schedule < T , U extends keyof T > ( queueName : string , target : T , method : U , ...args ) ;
251
316
public schedule ( queueName : string , target : any , method : any | Function , ...args ) ;
252
317
public schedule ( queueName , ..._args ) {
318
+ scheduleCount ++ ;
253
319
let [ target , method , args ] = parseArgs ( ..._args ) ;
254
320
let stack = this . DEBUG ? new Error ( ) : undefined ;
255
321
return this . _ensureInstance ( ) . schedule ( queueName , target , method , args , false , stack ) ;
@@ -264,6 +330,7 @@ export default class Backburner {
264
330
@return method result
265
331
*/
266
332
public scheduleIterable ( queueName : string , iterable : ( ) => Iteratable ) {
333
+ scheduleIterableCount ++ ;
267
334
let stack = this . DEBUG ? new Error ( ) : undefined ;
268
335
return this . _ensureInstance ( ) . schedule ( queueName , null , iteratorDrain , [ iterable ] , false , stack ) ;
269
336
}
@@ -272,6 +339,7 @@ export default class Backburner {
272
339
* @deprecated please use scheduleOnce instead.
273
340
*/
274
341
public deferOnce ( queueName , targetOrMethod , ...args ) {
342
+ deferOnceCount ++ ;
275
343
return this . scheduleOnce ( queueName , targetOrMethod , ...args ) ;
276
344
}
277
345
@@ -282,6 +350,7 @@ export default class Backburner {
282
350
public scheduleOnce < T , U extends keyof T > ( queueName : string , target : T , method : U , ...args ) ;
283
351
public scheduleOnce ( queueName : string , target : any | null , method : any | Function , ...args ) ;
284
352
public scheduleOnce ( queueName , ..._args ) {
353
+ scheduleOnceCount ++ ;
285
354
let [ target , method , args ] = parseArgs ( ..._args ) ;
286
355
let stack = this . DEBUG ? new Error ( ) : undefined ;
287
356
return this . _ensureInstance ( ) . schedule ( queueName , target , method , args , true , stack ) ;
@@ -292,10 +361,12 @@ export default class Backburner {
292
361
*/
293
362
public setTimeout ( ...args ) ;
294
363
public setTimeout ( ) {
364
+ setTimeoutCount ++ ;
295
365
return this . later ( ...arguments ) ;
296
366
}
297
367
298
368
public later ( ...args ) {
369
+ laterCount ++ ;
299
370
let length = args . length ;
300
371
301
372
let wait = 0 ;
@@ -349,6 +420,7 @@ export default class Backburner {
349
420
public throttle < A , B > ( method : ( arg1 : A , arg2 : B ) => void , arg1 : A , arg2 : B , wait ?: number | string , immediate ?: boolean ) : Timer ;
350
421
public throttle < A , B , C > ( method : ( arg1 : A , arg2 : B , arg3 : C ) => void , arg1 : A , arg2 : B , arg3 : C , wait ?: number | string , immediate ?: boolean ) : Timer ;
351
422
public throttle ( targetOrThisArgOrMethod : object | Function , ...args ) : Timer {
423
+ throttleCount ++ ;
352
424
let target ;
353
425
let method ;
354
426
let immediate ;
@@ -425,6 +497,7 @@ export default class Backburner {
425
497
public debounce < A , B > ( method : ( arg1 : A , arg2 : B ) => void , arg1 : A , arg2 : B , wait : number | string , immediate ?: boolean ) : Timer ;
426
498
public debounce < A , B , C > ( method : ( arg1 : A , arg2 : B , arg3 : C ) => void , arg1 : A , arg2 : B , arg3 : C , wait : number | string , immediate ?: boolean ) : Timer ;
427
499
public debounce ( targetOrThisArgOrMethod : object | Function , ...args ) : Timer {
500
+ debounceCount ++ ;
428
501
let target ;
429
502
let method ;
430
503
let immediate ;
@@ -487,6 +560,7 @@ export default class Backburner {
487
560
}
488
561
489
562
public cancelTimers ( ) {
563
+ cancelTimersCount ++ ;
490
564
for ( let i = 3 ; i < this . _throttlers . length ; i += 4 ) {
491
565
this . _platform . clearTimeout ( this . _throttlers [ i ] ) ;
492
566
}
@@ -511,6 +585,7 @@ export default class Backburner {
511
585
}
512
586
513
587
public cancel ( timer ?) {
588
+ cancelCount ++ ;
514
589
if ( ! timer ) { return false ; }
515
590
let timerType = typeof timer ;
516
591
@@ -693,6 +768,7 @@ export default class Backburner {
693
768
private _ensureInstance ( ) : DeferredActionQueues {
694
769
let currentInstance = this . currentInstance ;
695
770
if ( currentInstance === null ) {
771
+ autorunsCreatedCount ++ ;
696
772
currentInstance = this . begin ( ) ;
697
773
const next = this . _platform . next ;
698
774
this . _autorun = next ( this . _boundAutorunEnd ) ;
0 commit comments