File tree 2 files changed +32
-1
lines changed
2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ type EventTimer struct {
10
10
timer * time.Timer
11
11
done chan struct {}
12
12
wg sync.WaitGroup
13
+ once sync.Once
13
14
}
14
15
15
16
func NewEventTimer (task func ()) * EventTimer {
@@ -45,7 +46,10 @@ func (t *EventTimer) Stop() {
45
46
return
46
47
}
47
48
48
- close (t .done )
49
+ t .once .Do (func () {
50
+ close (t .done )
51
+ })
52
+
49
53
t .wg .Wait ()
50
54
}
51
55
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