@@ -45,6 +45,28 @@ function parseArgs() {
4545
4646let UUID = 0 ;
4747
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+
4870export default class Backburner {
4971 public static Queue = Queue ;
5072
@@ -54,6 +76,38 @@ export default class Backburner {
5476
5577 public options : any ;
5678
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+
57111 private _onBegin : ( currentInstance : DeferredActionQueues , previousInstance : DeferredActionQueues | null ) => void ;
58112 private _onEnd : ( currentInstance : DeferredActionQueues , nextInstance : DeferredActionQueues | null ) => void ;
59113 private queueNames : string [ ] ;
@@ -107,6 +161,7 @@ export default class Backburner {
107161 this . _boundRunExpiredTimers = this . _runExpiredTimers . bind ( this ) ;
108162
109163 this . _boundAutorunEnd = ( ) => {
164+ autorunsCompletedCount ++ ;
110165 this . _autorun = null ;
111166 this . end ( ) ;
112167 } ;
@@ -117,6 +172,7 @@ export default class Backburner {
117172 @return instantiated class DeferredActionQueues
118173 */
119174 public begin ( ) : DeferredActionQueues {
175+ beginCount ++ ;
120176 let options = this . options ;
121177 let previousInstance = this . currentInstance ;
122178 let current ;
@@ -126,9 +182,12 @@ export default class Backburner {
126182 this . _cancelAutorun ( ) ;
127183 } else {
128184 if ( previousInstance !== null ) {
185+ nestedDeferredActionQueuesCreated ++ ;
129186 this . instanceStack . push ( previousInstance ) ;
130187 }
188+ deferredActionQueuesCreatedCount ++ ;
131189 current = this . currentInstance = new DeferredActionQueues ( this . queueNames , options ) ;
190+ beginEventCount ++ ;
132191 this . _trigger ( 'begin' , current , previousInstance ) ;
133192 }
134193
@@ -138,6 +197,7 @@ export default class Backburner {
138197 }
139198
140199 public end ( ) {
200+ endCount ++ ;
141201 let currentInstance = this . currentInstance ;
142202 let nextInstance : DeferredActionQueues | null = null ;
143203
@@ -156,6 +216,7 @@ export default class Backburner {
156216 finallyAlreadyCalled = true ;
157217
158218 if ( result === QUEUE_STATE . Pause ) {
219+ autorunsCreatedCount ++ ;
159220 const next = this . _platform . next ;
160221 this . _autorun = next ( this . _boundAutorunEnd ) ;
161222 } else {
@@ -165,6 +226,7 @@ export default class Backburner {
165226 nextInstance = this . instanceStack . pop ( ) as DeferredActionQueues ;
166227 this . currentInstance = nextInstance ;
167228 }
229+ endEventCount ++ ;
168230 this . _trigger ( 'end' , currentInstance , nextInstance ) ;
169231 this . _onEnd ( currentInstance , nextInstance ) ;
170232 }
@@ -208,6 +270,7 @@ export default class Backburner {
208270 public run ( target : Function | any | null , method ?: Function | string , ...args ) ;
209271 public run ( target : any | null | undefined , method ?: Function , ...args : any [ ] ) ;
210272 public run ( ) {
273+ runCount ++ ;
211274 let [ target , method , args ] = parseArgs ( ...arguments ) ;
212275 return this . _run ( target , method , args ) ;
213276 }
@@ -230,6 +293,7 @@ export default class Backburner {
230293 public join ( target : Function | any | null , method ?: Function | string , ...args ) ;
231294 public join ( target : any | null | undefined , method ?: Function , ...args : any [ ] ) ;
232295 public join ( ) {
296+ joinCount ++ ;
233297 let [ target , method , args ] = parseArgs ( ...arguments ) ;
234298 return this . _join ( target , method , args ) ;
235299 }
@@ -238,6 +302,7 @@ export default class Backburner {
238302 * @deprecated please use schedule instead.
239303 */
240304 public defer ( queueName , targetOrMethod , ..._args ) {
305+ deferCount ++ ;
241306 return this . schedule ( queueName , targetOrMethod , ..._args ) ;
242307 }
243308
@@ -248,6 +313,7 @@ export default class Backburner {
248313 public schedule < T , U extends keyof T > ( queueName : string , target : T , method : U , ...args ) ;
249314 public schedule ( queueName : string , target : any , method : any | Function , ...args ) ;
250315 public schedule ( queueName , ..._args ) {
316+ scheduleCount ++ ;
251317 let [ target , method , args ] = parseArgs ( ..._args ) ;
252318 let stack = this . DEBUG ? new Error ( ) : undefined ;
253319 return this . _ensureInstance ( ) . schedule ( queueName , target , method , args , false , stack ) ;
@@ -262,6 +328,7 @@ export default class Backburner {
262328 @return method result
263329 */
264330 public scheduleIterable ( queueName : string , iterable : ( ) => Iteratable ) {
331+ scheduleIterableCount ++ ;
265332 let stack = this . DEBUG ? new Error ( ) : undefined ;
266333 return this . _ensureInstance ( ) . schedule ( queueName , null , iteratorDrain , [ iterable ] , false , stack ) ;
267334 }
@@ -270,6 +337,7 @@ export default class Backburner {
270337 * @deprecated please use scheduleOnce instead.
271338 */
272339 public deferOnce ( queueName , targetOrMethod , ...args ) {
340+ deferOnceCount ++ ;
273341 return this . scheduleOnce ( queueName , targetOrMethod , ...args ) ;
274342 }
275343
@@ -280,6 +348,7 @@ export default class Backburner {
280348 public scheduleOnce < T , U extends keyof T > ( queueName : string , target : T , method : U , ...args ) ;
281349 public scheduleOnce ( queueName : string , target : any | null , method : any | Function , ...args ) ;
282350 public scheduleOnce ( queueName , ..._args ) {
351+ scheduleOnceCount ++ ;
283352 let [ target , method , args ] = parseArgs ( ..._args ) ;
284353 let stack = this . DEBUG ? new Error ( ) : undefined ;
285354 return this . _ensureInstance ( ) . schedule ( queueName , target , method , args , true , stack ) ;
@@ -290,10 +359,12 @@ export default class Backburner {
290359 */
291360 public setTimeout ( ...args ) ;
292361 public setTimeout ( ) {
362+ setTimeoutCount ++ ;
293363 return this . later ( ...arguments ) ;
294364 }
295365
296366 public later ( ...args ) {
367+ laterCount ++ ;
297368 let length = args . length ;
298369
299370 let wait = 0 ;
@@ -347,6 +418,7 @@ export default class Backburner {
347418 public throttle < A , B > ( method : ( arg1 : A , arg2 : B ) => void , arg1 : A , arg2 : B , wait ?: number | string , immediate ?: boolean ) : Timer ;
348419 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 ;
349420 public throttle ( targetOrThisArgOrMethod : object | Function , ...args ) : Timer {
421+ throttleCount ++ ;
350422 let target ;
351423 let method ;
352424 let immediate ;
@@ -423,6 +495,7 @@ export default class Backburner {
423495 public debounce < A , B > ( method : ( arg1 : A , arg2 : B ) => void , arg1 : A , arg2 : B , wait : number | string , immediate ?: boolean ) : Timer ;
424496 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 ;
425497 public debounce ( targetOrThisArgOrMethod : object | Function , ...args ) : Timer {
498+ debounceCount ++ ;
426499 let target ;
427500 let method ;
428501 let immediate ;
@@ -485,6 +558,7 @@ export default class Backburner {
485558 }
486559
487560 public cancelTimers ( ) {
561+ cancelTimersCount ++ ;
488562 for ( let i = 3 ; i < this . _throttlers . length ; i += 4 ) {
489563 this . _platform . clearTimeout ( this . _throttlers [ i ] ) ;
490564 }
@@ -509,9 +583,11 @@ export default class Backburner {
509583 }
510584
511585 public cancel ( timer ?) {
586+ cancelCount ++ ;
587+
512588 if ( timer === undefined || timer === null ) { return false ; }
589+
513590 let timerType = typeof timer ;
514-
515591 if ( timerType === 'number' ) { // we're cancelling a throttle or debounce
516592 return this . _cancelItem ( timer , this . _throttlers ) || this . _cancelItem ( timer , this . _debouncees ) ;
517593 } else if ( timerType === 'string' ) { // we're cancelling a setTimeout
@@ -688,6 +764,7 @@ export default class Backburner {
688764 private _ensureInstance ( ) : DeferredActionQueues {
689765 let currentInstance = this . currentInstance ;
690766 if ( currentInstance === null ) {
767+ autorunsCreatedCount ++ ;
691768 currentInstance = this . begin ( ) ;
692769 const next = this . _platform . next ;
693770 this . _autorun = next ( this . _boundAutorunEnd ) ;
0 commit comments