Skip to content

Commit

Permalink
make sure that timer callback hasn't already been removed by another …
Browse files Browse the repository at this point in the history
…listener during emit(), see #248
  • Loading branch information
jessegreenberg committed May 17, 2019
1 parent d845ea4 commit 9229be6
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions js/timer.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@ define( require => {

// Convert seconds to ms and see if item has timed out
if ( elapsed * 1000 >= timeout ) {
listener();
this.removeListener( callback );

// make sure that this callback hasn't already been removed by another listener while emit() is in progress
if ( this.hasListener( callback ) ) {
listener();
this.removeListener( callback );
}
}
};
this.addListener( callback );
Expand Down

0 comments on commit 9229be6

Please sign in to comment.