Skip to content

Commit

Permalink
add more annotation about the timing of that stream was closed for ex…
Browse files Browse the repository at this point in the history
…ample code (#41)
  • Loading branch information
goodbye-babyer authored Sep 20, 2023
1 parent 9f40696 commit a55c797
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 2 additions & 3 deletions example/best_practice/shmipc_async_client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func init() {
runtime.GOMAXPROCS(1)

go func() {
http.ListenAndServe(":20001", nil)//nolint:errcheck
http.ListenAndServe(":20001", nil) //nolint:errcheck
}()
}

Expand Down Expand Up @@ -132,7 +132,6 @@ func main() {

for i := 0; i < concurrency; i++ {
go func() {
//for range time.Tick(time.Second) {
key := make([]byte, 1024)
rand.Read(key)
s := &streamCbImpl{key: key, smgr: smgr, loop: math.MaxUint64}
Expand All @@ -145,7 +144,7 @@ func main() {
s.n = 0
stream.SetCallbacks(s)
s.send()
//}
// and maybe call `smgr.PutBack()` or `stream.Close()` when you are no longer using the stream.
}()
}

Expand Down
4 changes: 4 additions & 0 deletions example/best_practice/shmipc_client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ func main() {

atomic.AddUint64(&count, 1)
}

//call `PutBack` return the stream to the stream pool for next time use, which will improve performance.
smgr.PutBack(stream)
//or call `stream.Close` the close Stream, otherwise it will be leak.
}
}()
}
Expand Down

0 comments on commit a55c797

Please sign in to comment.