File tree Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ type EventTimer struct {
1010 timer * time.Timer
1111 done chan struct {}
1212 wg sync.WaitGroup
13+ once sync.Once
1314}
1415
1516func NewEventTimer (task func ()) * EventTimer {
@@ -45,7 +46,10 @@ func (t *EventTimer) Stop() {
4546 return
4647 }
4748
48- close (t .done )
49+ t .once .Do (func () {
50+ close (t .done )
51+ })
52+
4953 t .wg .Wait ()
5054}
5155
Original file line number Diff line number Diff line change 1+ // Copyright (c) quickfixengine.org All rights reserved.
2+ //
3+ // This file may be distributed under the terms of the quickfixengine.org
4+ // license as defined by quickfixengine.org and appearing in the file
5+ // LICENSE included in the packaging of this file.
6+ //
7+ // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING
8+ // THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A
9+ // PARTICULAR PURPOSE.
10+ //
11+ // See http://www.quickfixengine.org/LICENSE for licensing information.
12+ //
13+ // Contact [email protected] if any conditions of this licensing 14+ // are not clear to you.
15+
16+ package internal
17+
18+ import (
19+ "testing"
20+ )
21+
22+ func TestEventTimer_Stop_idempotent (* testing.T ) {
23+ t := NewEventTimer (func () {})
24+
25+ t .Stop ()
26+ t .Stop ()
27+ }
You can’t perform that action at this time.
0 commit comments