File tree 3 files changed +6
-10
lines changed
3 files changed +6
-10
lines changed Original file line number Diff line number Diff line change 1
1
# Problem 7
2
2
3
- ` runTasks ` need to initialize some conf and we need to run it only once.
3
+ Identify the data race in ` task ` . Fix the issue.
4
+
5
+ NOTE: don't forget to run test with ` -race ` flag
Original file line number Diff line number Diff line change @@ -6,14 +6,12 @@ import (
6
6
"time"
7
7
)
8
8
9
- //TODO: identify the data race
10
- // fix the issue.
11
-
12
9
func task () {
13
10
start := time .Now ()
14
11
var t * time.Timer
15
12
t = time .AfterFunc (
16
- randomDuration (), func () {
13
+ randomDuration (),
14
+ func () {
17
15
fmt .Println (time .Now ().Sub (start ))
18
16
t .Reset (randomDuration ())
19
17
},
Original file line number Diff line number Diff line change @@ -6,12 +6,8 @@ import (
6
6
7
7
func TestTask (t * testing.T ) {
8
8
t .Run (
9
- "init should run one only once " , func (t * testing.T ) {
9
+ "should avoid data race " , func (t * testing.T ) {
10
10
task ()
11
-
12
- if 0 != 1 {
13
- t .Errorf ("init function run times wrong" )
14
- }
15
11
},
16
12
)
17
13
}
You can’t perform that action at this time.
0 commit comments