From 500a965df27ab122f9729b514ef64ffefe4b255b Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 17 Sep 2019 22:37:13 -0400 Subject: [PATCH] Increase default channel capacity to 100, and allow it to be set in RunOptions --- chat.go | 7 ++++++- types.go | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/chat.go b/chat.go index 381dd01..b86f8c6 100644 --- a/chat.go +++ b/chat.go @@ -52,8 +52,13 @@ func getNewMessages(k *Keybase, c chan<- ChatAPI, execOptions []string) { // Run runs `keybase chat api-listen`, and passes incoming messages to the message handler func func (k *Keybase) Run(handler func(ChatAPI), options ...RunOptions) { var heartbeatFreq int64 + var channelCapacity = 100 + runOptions := make([]string, 0) if len(options) > 0 { + if options[0].Capacity > 0 { + channelCapacity = options[0].Capacity + } if options[0].Heartbeat > 0 { heartbeatFreq = options[0].Heartbeat } @@ -76,7 +81,7 @@ func (k *Keybase) Run(handler func(ChatAPI), options ...RunOptions) { runOptions = append(runOptions, createFilterString(options[0].FilterChannel)) } } - c := make(chan ChatAPI, 50) + c := make(chan ChatAPI, channelCapacity) defer close(c) if heartbeatFreq > 0 { go heartbeat(c, time.Duration(heartbeatFreq)*time.Minute) diff --git a/types.go b/types.go index bbf54bf..4121a90 100644 --- a/types.go +++ b/types.go @@ -2,6 +2,7 @@ package keybase // RunOptions holds a set of options to be passed to Run type RunOptions struct { + Capacity int // Channel capacity for the buffered channel that holds messages. Defaults to 100 if not set Heartbeat int64 // Send a heartbeat through the channel every X minutes (0 = off) Local bool // Subscribe to local messages HideExploding bool // Ignore exploding messages