Browse Source

Increase default channel capacity to 100, and allow it to be set in RunOptions

main
Sam 5 years ago
parent
commit
500a965df2
  1. 7
      chat.go
  2. 1
      types.go

7
chat.go

@ -52,8 +52,13 @@ func getNewMessages(k *Keybase, c chan<- ChatAPI, execOptions []string) { @@ -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) { @@ -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)

1
types.go

@ -2,6 +2,7 @@ package keybase @@ -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

Loading…
Cancel
Save