Skip to content

Commit

Permalink
Merge pull request #1169 from lololozhkin/socketmode-runEventLoopContext
Browse files Browse the repository at this point in the history
implemented RunEventLoopContext method. now socketmodehandler will react on context cancellation
  • Loading branch information
kanata2 committed Apr 13, 2023
2 parents 7f50a78 + 39c076e commit 5281ebe
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions socketmode/socketmode_handler.go
@@ -1,6 +1,7 @@
package socketmode

import (
"context"

Check failure on line 4 in socketmode/socketmode_handler.go

View workflow job for this annotation

GitHub Actions / lint

File is not `goimports`-ed (goimports)
"github.com/slack-go/slack"
"github.com/slack-go/slack/slackevents"
)
Expand Down Expand Up @@ -105,15 +106,31 @@ func (r *SocketmodeHandler) HandleDefault(f SocketmodeHandlerFunc) {
// RunSlackEventLoop receives the event via the socket
func (r *SocketmodeHandler) RunEventLoop() error {

go r.runEventLoop()
go r.runEventLoop(context.Background())

return r.Client.Run()
}

func (r *SocketmodeHandler) RunEventLoopContext(ctx context.Context) error {
go r.runEventLoop(ctx)

return r.Client.RunContext(ctx)
}

// Call the dispatcher for each incomming event
func (r *SocketmodeHandler) runEventLoop() {
for evt := range r.Client.Events {
r.dispatcher(evt)
func (r *SocketmodeHandler) runEventLoop(ctx context.Context) {
for {
select {
case evt, ok := <-r.Client.Events:
if !ok {
return
}

r.dispatcher(evt)

case <-ctx.Done():
return
}
}
}

Expand Down

0 comments on commit 5281ebe

Please sign in to comment.