@@ -50,27 +50,41 @@ function startLoop() {
5050 asyncHook . enable ( ) ;
5151
5252 setTimeoutNode = global . setTimeout ;
53-
54- global . setTimeout = function ( cb , t ) {
53+ global . setTimeout = function ( cb , timeout ) {
54+ const timeoutHandle = { running : true } ;
5555 const args = Array . prototype . slice . call ( arguments , 2 ) ;
56- return binding . lib . setTimeout ( function ( ) {
57- cb . apply ( null , args ) ;
58- } , t ) ;
59- } ;
56+ binding . lib . Ui . startTimer ( timeout , function ( ) {
57+ if ( timeoutHandle . running ) {
58+ cb . apply ( null , args ) ;
59+ }
60+ return false ;
61+ } ) ;
62+ return timeoutHandle ;
63+ }
6064
6165 clearTimeoutNode = global . clearTimeout ;
62- global . clearTimeout = binding . lib . clearTimeout ;
66+ global . clearTimeout = function ( timeoutHandle ) {
67+ timeoutHandle . running = false ;
68+ }
6369
6470 setIntervalNode = global . setInterval ;
65- global . setInterval = function ( cb , t ) {
71+ global . setInterval = function ( cb , timeout ) {
72+ const timeoutHandle = { running : true } ;
6673 const args = Array . prototype . slice . call ( arguments , 2 ) ;
67- return binding . lib . setInterval ( function ( ) {
68- cb . apply ( null , args ) ;
69- } , t ) ;
70- } ;
74+ binding . lib . Ui . startTimer ( timeout , function ( ) {
75+ if ( timeoutHandle . running ) {
76+ cb . apply ( null , args ) ;
77+ return true ;
78+ }
79+ return false ;
80+ } ) ;
81+ return timeoutHandle ;
82+ }
7183
7284 clearIntervalNode = global . clearInterval ;
73- global . clearInterval = binding . lib . clearInterval ;
85+ global . clearInterval = function ( timeoutHandle ) {
86+ timeoutHandle . running = false ;
87+ }
7488}
7589
7690// This is called when a new async handle
0 commit comments