Run gofmt -s -w .

This commit is contained in:
Neil Alexander 2018-01-04 22:37:51 +00:00
parent ae7b07ae6a
commit b3ebe76b59
45 changed files with 5037 additions and 4288 deletions

View file

@ -6,47 +6,51 @@ import "time"
import "fmt"
type testStruct struct {
First uint64
Second float64
Third []byte
First uint64
Second float64
Third []byte
}
func testFunc(tickerDuration time.Duration) {
chn := make(chan []byte)
ticker := time.NewTicker(tickerDuration)
defer ticker.Stop()
send := testStruct{First: 1, Second: 2, Third: []byte{3, 4, 5}}
buf := bytes.NewBuffer(nil)
enc := gob.NewEncoder(buf)
dec := gob.NewDecoder(buf)
sendCall := func () {
err := enc.EncodeValue(&send)
if err != nil { panic(err) }
bs := make([]byte, buf.Len())
buf.Read(bs)
fmt.Println("send:", bs)
go func() { chn<-bs }()
}
recvCall := func (bs []byte) {
buf.Write(bs)
recv := testStruct{}
err := dec.DecodeValue(&recv)
fmt.Println("recv:", bs)
if err != nil { panic(err) }
}
for {
select {
case bs := <-chn : recvCall(bs)
case <-ticker.C : sendCall()
}
}
chn := make(chan []byte)
ticker := time.NewTicker(tickerDuration)
defer ticker.Stop()
send := testStruct{First: 1, Second: 2, Third: []byte{3, 4, 5}}
buf := bytes.NewBuffer(nil)
enc := gob.NewEncoder(buf)
dec := gob.NewDecoder(buf)
sendCall := func() {
err := enc.EncodeValue(&send)
if err != nil {
panic(err)
}
bs := make([]byte, buf.Len())
buf.Read(bs)
fmt.Println("send:", bs)
go func() { chn <- bs }()
}
recvCall := func(bs []byte) {
buf.Write(bs)
recv := testStruct{}
err := dec.DecodeValue(&recv)
fmt.Println("recv:", bs)
if err != nil {
panic(err)
}
}
for {
select {
case bs := <-chn:
recvCall(bs)
case <-ticker.C:
sendCall()
}
}
}
func main() {
go testFunc(100*time.Millisecond) // Does not crash
time.Sleep(time.Second)
go testFunc(time.Nanosecond) // Does crash
time.Sleep(time.Second)
go testFunc(100 * time.Millisecond) // Does not crash
time.Sleep(time.Second)
go testFunc(time.Nanosecond) // Does crash
time.Sleep(time.Second)
}