@@ -32,6 +32,14 @@ const noop = function() {};
3232
3333const DISABLE_SCHEDULE = Object . freeze ( [ ] ) ;
3434
35+ interface ConsoleWithCreateTask extends Console {
36+ createTask ( name : string ) : ConsoleTask ;
37+ }
38+
39+ interface ConsoleTask {
40+ run < T > ( f : ( ) => T ) : T ;
41+ }
42+
3543function parseArgs ( ...args : any [ ] ) ;
3644function parseArgs ( ) {
3745 let length = arguments . length ;
@@ -163,6 +171,7 @@ export default class Backburner {
163171 public static buildNext = buildNext ;
164172
165173 public DEBUG = false ;
174+ public ASYNC_STACKS = false ;
166175
167176 public currentInstance : DeferredActionQueues | null = null ;
168177
@@ -371,7 +380,8 @@ export default class Backburner {
371380 scheduleCount ++ ;
372381 let [ target , method , args ] = parseArgs ( ..._args ) ;
373382 let stack = this . DEBUG ? new Error ( ) : undefined ;
374- return this . _ensureInstance ( ) . schedule ( queueName , target , method , args , false , stack ) ;
383+ let consoleTask = this . createTask ( queueName , method ) ;
384+ return this . _ensureInstance ( ) . schedule ( queueName , target , method , args , false , stack , consoleTask ) ;
375385 }
376386
377387 /*
@@ -385,7 +395,8 @@ export default class Backburner {
385395 public scheduleIterable ( queueName : string , iterable : ( ) => Iterable ) {
386396 scheduleIterableCount ++ ;
387397 let stack = this . DEBUG ? new Error ( ) : undefined ;
388- return this . _ensureInstance ( ) . schedule ( queueName , null , iteratorDrain , [ iterable ] , false , stack ) ;
398+ let consoleTask = this . createTask ( queueName , null ) ;
399+ return this . _ensureInstance ( ) . schedule ( queueName , null , iteratorDrain , [ iterable ] , false , stack , consoleTask ) ;
389400 }
390401
391402 /**
@@ -406,7 +417,8 @@ export default class Backburner {
406417 scheduleOnceCount ++ ;
407418 let [ target , method , args ] = parseArgs ( ..._args ) ;
408419 let stack = this . DEBUG ? new Error ( ) : undefined ;
409- return this . _ensureInstance ( ) . schedule ( queueName , target , method , args , true , stack ) ;
420+ let consoleTask = this . createTask ( queueName , method ) ;
421+ return this . _ensureInstance ( ) . schedule ( queueName , target , method , args , true , stack , consoleTask ) ;
410422 }
411423
412424 /**
@@ -525,7 +537,8 @@ export default class Backburner {
525537 _timers [ argIndex ] = args ;
526538 } else {
527539 let stack = this . _timers [ index + 5 ] ;
528- this . _timers . splice ( i , 0 , executeAt , timerId , target , method , args , stack ) ;
540+ let consoleTask = this . _timers [ index + 6 ] ;
541+ this . _timers . splice ( i , 0 , executeAt , timerId , target , method , args , stack , consoleTask ) ;
529542 this . _timers . splice ( index , TIMERS_OFFSET ) ;
530543 }
531544
@@ -666,16 +679,17 @@ export default class Backburner {
666679
667680 private _later ( target , method , args , wait ) {
668681 let stack = this . DEBUG ? new Error ( ) : undefined ;
682+ let consoleTask = this . createTask ( "(timer)" , method ) ;
669683 let executeAt = this . _platform . now ( ) + wait ;
670684 let id = UUID ++ ;
671685
672686 if ( this . _timers . length === 0 ) {
673- this . _timers . push ( executeAt , id , target , method , args , stack ) ;
687+ this . _timers . push ( executeAt , id , target , method , args , stack , consoleTask ) ;
674688 this . _installTimerTimeout ( ) ;
675689 } else {
676690 // find position to insert
677691 let i = searchTimer ( executeAt , this . _timers ) ;
678- this . _timers . splice ( i , 0 , executeAt , id , target , method , args , stack ) ;
692+ this . _timers . splice ( i , 0 , executeAt , id , target , method , args , stack , consoleTask ) ;
679693
680694 // always reinstall since it could be out of sync
681695 this . _reinstallTimerTimeout ( ) ;
@@ -741,7 +755,8 @@ export default class Backburner {
741755 let target = timers [ i + 2 ] ;
742756 let method = timers [ i + 3 ] ;
743757 let stack = timers [ i + 5 ] ;
744- this . currentInstance ! . schedule ( defaultQueue , target , method , args , false , stack ) ;
758+ let consoleTask = timers [ i + 6 ] ;
759+ this . currentInstance ! . schedule ( defaultQueue , target , method , args , false , stack , consoleTask ) ;
745760 }
746761 }
747762
@@ -792,4 +807,12 @@ export default class Backburner {
792807
793808 this . _autorun = true ;
794809 }
810+
811+ private createTask ( queueName , method ) {
812+ if ( this . ASYNC_STACKS && console [ "createTask" ] ) {
813+ return ( < ConsoleWithCreateTask > console ) . createTask (
814+ `runloop ${ queueName } | ${ method ?. name || "<anonymous>" } `
815+ ) ;
816+ }
817+ }
795818}
0 commit comments