File tree Expand file tree Collapse file tree 2 files changed +25
-2
lines changed Expand file tree Collapse file tree 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) {
211211
212212function Timeout ( fn , time ) {
213213 var timer = false ;
214+ var func = ( ) => {
215+ if ( timer ) {
216+ clearTimeout ( timer ) ;
217+ timer = false ;
218+
219+ fn ( ) ;
220+ }
221+ } ;
214222
215223 this . start = function ( ) {
216224 if ( ! this . isRunning ( ) ) {
217- timer = setTimeout ( fn , time ) ;
225+ timer = setTimeout ( func , time ) ;
218226 }
219227 return this ;
220228 } ;
@@ -226,7 +234,6 @@ function Timeout(fn, time) {
226234 } ;
227235
228236 this . isRunning = function ( ) {
229- if ( timer && timer . _called ) return false ;
230237 return timer !== false ;
231238 } ;
232239}
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