Skip to content

Commit

Permalink
Use js.wait for nil context
Browse files Browse the repository at this point in the history
  • Loading branch information
nsurfer committed Feb 22, 2021
1 parent ffee0ba commit 12257af
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions jsm.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,19 @@ type consumerLister struct {

// ConsumersInfo returns a receive only channel to iterate on the consumers info.
func (js *js) ConsumersInfo(ctx context.Context, stream string) <-chan *ConsumerInfo {
var cancel context.CancelFunc
if ctx == nil {
ctx, cancel = context.WithTimeout(context.Background(), js.wait)
}

ach := make(chan *ConsumerInfo)
cl := &consumerLister{stream: stream, js: js}
go func() {
defer func() {
if cancel != nil {
cancel()
}
}()
defer close(ach)
for cl.Next() {
for _, info := range cl.Page() {
Expand Down Expand Up @@ -629,9 +639,19 @@ type streamLister struct {

// StreamsInfo returns a receive only channel to iterate on the streams.
func (js *js) StreamsInfo(ctx context.Context) <-chan *StreamInfo {
var cancel context.CancelFunc
if ctx == nil {
ctx, cancel = context.WithTimeout(context.Background(), js.wait)
}

ach := make(chan *StreamInfo)
sl := &streamLister{js: js}
go func() {
defer func() {
if cancel != nil {
cancel()
}
}()
defer close(ach)
for sl.Next() {
for _, info := range sl.Page() {
Expand Down

0 comments on commit 12257af

Please sign in to comment.