File tree 2 files changed +25
-2
lines changed
2 files changed +25
-2
lines changed Original file line number Diff line number Diff line change @@ -211,10 +211,18 @@ function Interval(fn, time) {
211
211
212
212
function Timeout ( fn , time ) {
213
213
var timer = false ;
214
+ var func = ( ) => {
215
+ if ( timer ) {
216
+ clearTimeout ( timer ) ;
217
+ timer = false ;
218
+
219
+ fn ( ) ;
220
+ }
221
+ } ;
214
222
215
223
this . start = function ( ) {
216
224
if ( ! this . isRunning ( ) ) {
217
- timer = setTimeout ( fn , time ) ;
225
+ timer = setTimeout ( func , time ) ;
218
226
}
219
227
return this ;
220
228
} ;
@@ -226,7 +234,6 @@ function Timeout(fn, time) {
226
234
} ;
227
235
228
236
this . isRunning = function ( ) {
229
- if ( timer && timer . _called ) return false ;
230
237
return timer !== false ;
231
238
} ;
232
239
}
Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+ const Timeout = require ( '../../../../lib/core/topologies/shared' ) . Timeout ;
3
+ const expect = require ( 'chai' ) . expect ;
4
+
5
+ describe ( '' , function ( ) {
6
+ it ( 'should detect when a timer is finished running' , function ( done ) {
7
+ let timeout ;
8
+ function timeoutHandler ( ) {
9
+ expect ( timeout . isRunning ( ) ) . to . be . false ;
10
+ done ( ) ;
11
+ }
12
+
13
+ timeout = new Timeout ( timeoutHandler , 100 ) ;
14
+ timeout . start ( ) ;
15
+ } ) ;
16
+ } ) ;
You can’t perform that action at this time.
0 commit comments