@@ -43,6 +43,8 @@ function parseArgs() {
4343 return [ target , method , args ] ;
4444}
4545
46+ let UUID = 0 ;
47+
4648export default class Backburner {
4749 public static Queue = Queue ;
4850
@@ -327,25 +329,7 @@ export default class Backburner {
327329 }
328330 }
329331
330- let onError = getOnError ( this . options ) ;
331- let executeAt = this . _platform . now ( ) + wait ;
332-
333- let fn ;
334- if ( onError ) {
335- fn = function ( ) {
336- try {
337- method . apply ( target , args ) ;
338- } catch ( e ) {
339- onError ( e ) ;
340- }
341- } ;
342- } else {
343- fn = function ( ) {
344- method . apply ( target , args ) ;
345- } ;
346- }
347-
348- return this . _setTimeout ( fn , executeAt ) ;
332+ return this . _setTimeout ( target , method , args , wait ) ;
349333 }
350334
351335 public throttle < T > ( target : T , methodName : keyof T , wait ?: number | string , immediate ?: boolean ) : Timer ;
@@ -530,9 +514,9 @@ export default class Backburner {
530514 if ( ! timer ) { return false ; }
531515 let timerType = typeof timer ;
532516
533- if ( timerType === 'number' || timerType === 'string' ) { // we're cancelling a throttle or debounce
517+ if ( timerType === 'number' ) { // we're cancelling a throttle or debounce
534518 return this . _cancelItem ( timer , this . _throttlers ) || this . _cancelItem ( timer , this . _debouncees ) ;
535- } else if ( timerType === 'function ' ) { // we're cancelling a setTimeout
519+ } else if ( timerType === 'string ' ) { // we're cancelling a setTimeout
536520 return this . _cancelLaterTimer ( timer ) ;
537521 } else if ( timerType === 'object' && timer . queue && timer . method ) { // we're cancelling a deferOnce
538522 return timer . queue . cancel ( timer ) ;
@@ -586,31 +570,34 @@ export default class Backburner {
586570 }
587571 }
588572
589- private _setTimeout ( fn , executeAt ) {
573+ private _setTimeout ( target , method , args , wait ) {
574+ let stack = this . DEBUG ? new Error ( ) : undefined ;
575+ let executeAt = this . _platform . now ( ) + wait ;
576+ let id = ( UUID ++ ) + '' ;
577+
590578 if ( this . _timers . length === 0 ) {
591- this . _timers . push ( executeAt , fn ) ;
579+ this . _timers . push ( executeAt , id , target , method , args , stack ) ;
592580 this . _installTimerTimeout ( ) ;
593- return fn ;
581+ return id ;
594582 }
595583
596584 // find position to insert
597585 let i = searchTimer ( executeAt , this . _timers ) ;
598-
599- this . _timers . splice ( i , 0 , executeAt , fn ) ;
586+ this . _timers . splice ( i , 0 , executeAt , id , target , method , args , stack ) ;
600587
601588 // we should be the new earliest timer if i == 0
602589 if ( i === 0 ) {
603590 this . _reinstallTimerTimeout ( ) ;
604591 }
605592
606- return fn ;
593+ return id ;
607594 }
608595
609596 private _cancelLaterTimer ( timer ) {
610- for ( let i = 1 ; i < this . _timers . length ; i += 2 ) {
597+ for ( let i = 1 ; i < this . _timers . length ; i += 6 ) {
611598 if ( this . _timers [ i ] === timer ) {
612599 i = i - 1 ;
613- this . _timers . splice ( i , 2 ) ; // remove the two elements
600+ this . _timers . splice ( i , 6 ) ;
614601 if ( i === 0 ) {
615602 this . _reinstallTimerTimeout ( ) ;
616603 }
@@ -662,15 +649,19 @@ export default class Backburner {
662649
663650 private _scheduleExpiredTimers ( ) {
664651 let timers = this . _timers ;
665- let l = timers . length ;
666652 let i = 0 ;
653+ let l = timers . length ;
667654 let defaultQueue = this . options . defaultQueue ;
668655 let n = this . _platform . now ( ) ;
669- for ( ; i < l ; i += 2 ) {
656+
657+ for ( ; i < l ; i += 6 ) {
670658 let executeAt = timers [ i ] ;
671659 if ( executeAt <= n ) {
672- let fn = timers [ i + 1 ] ;
673- this . schedule ( defaultQueue , null , fn ) ;
660+ let target = timers [ i + 2 ] ;
661+ let method = timers [ i + 3 ] ;
662+ let args = timers [ i + 4 ] ;
663+ let stack = timers [ i + 5 ] ;
664+ this . currentInstance ! . schedule ( defaultQueue , target , method , args , false , stack ) ;
674665 } else {
675666 break ;
676667 }
0 commit comments