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 @@ -213,10 +213,18 @@ function Interval(fn, time) {
213
213
214
214
function Timeout ( fn , time ) {
215
215
var timer = false ;
216
+ var func = ( ) => {
217
+ if ( timer ) {
218
+ clearTimeout ( timer ) ;
219
+ timer = false ;
220
+
221
+ fn ( ) ;
222
+ }
223
+ } ;
216
224
217
225
this . start = function ( ) {
218
226
if ( ! this . isRunning ( ) ) {
219
- timer = setTimeout ( fn , time ) ;
227
+ timer = setTimeout ( func , time ) ;
220
228
}
221
229
return this ;
222
230
} ;
@@ -228,7 +236,6 @@ function Timeout(fn, time) {
228
236
} ;
229
237
230
238
this . isRunning = function ( ) {
231
- if ( timer && timer . _called ) return false ;
232
239
return timer !== false ;
233
240
} ;
234
241
}
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