Skip to content

Commit 5ff21cc

Browse files
committed
stack: try to make the example less racy
This is a bit crappy, as we want the select {} clause to be run before the panic() call, but I'm not away of any way to synchronize such thing.
1 parent dcebf30 commit 5ff21cc

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

stack/example_test.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,20 @@ import (
2121
func Example_text() {
2222
source := `package main
2323
24+
import "time"
25+
2426
func main() {
2527
c := crashy{}
26-
go c.die(42.)
28+
go func() {
29+
c.die(42.)
30+
}()
2731
select {}
2832
}
2933
30-
type crashy struct {}
34+
type crashy struct{}
3135
3236
func (c crashy) die(f float64) {
37+
time.Sleep(time.Millisecond)
3338
panic(int(f))
3439
}`
3540

@@ -105,10 +110,11 @@ func Example_text() {
105110
// Output:
106111
// panic: 42
107112
//
108-
// 1: running [Created by main.main @ main.go:5]
109-
// main main.go:12 crashy.die(42)
113+
// 1: running [Created by main.main @ main.go:7]
114+
// main main.go:17 crashy.die(42)
115+
// main main.go:8 main.func1()
110116
// 1: select (no cases)
111-
// main main.go:6 main()
117+
// main main.go:10 main()
112118
// exit status 2
113119
}
114120

0 commit comments

Comments
 (0)