summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/nlopes/slack/websocket.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2019-09-07 22:46:58 +0200
committerGitHub <noreply@github.com>2019-09-07 22:46:58 +0200
commita3bee01e0af3394c19360b98fd2db1b647f49299 (patch)
treeffc5778361d55d592a718354a37c9251e75fc7f6 /vendor/github.com/nlopes/slack/websocket.go
parent1dc93ec4f001edd01daccbe408767d4878be25a3 (diff)
downloadmatterbridge-msglm-a3bee01e0af3394c19360b98fd2db1b647f49299.tar.gz
matterbridge-msglm-a3bee01e0af3394c19360b98fd2db1b647f49299.tar.bz2
matterbridge-msglm-a3bee01e0af3394c19360b98fd2db1b647f49299.zip
Update dependencies (#886)
Diffstat (limited to 'vendor/github.com/nlopes/slack/websocket.go')
-rw-r--r--vendor/github.com/nlopes/slack/websocket.go38
1 files changed, 17 insertions, 21 deletions
diff --git a/vendor/github.com/nlopes/slack/websocket.go b/vendor/github.com/nlopes/slack/websocket.go
index e5dee68a..122807b9 100644
--- a/vendor/github.com/nlopes/slack/websocket.go
+++ b/vendor/github.com/nlopes/slack/websocket.go
@@ -2,7 +2,6 @@ package slack
import (
"encoding/json"
- "errors"
"net/url"
"sync"
"time"
@@ -33,11 +32,10 @@ type RTM struct {
IncomingEvents chan RTMEvent
outgoingMessages chan OutgoingMessage
killChannel chan bool
- disconnected chan struct{} // disconnected is closed when Disconnect is invoked, regardless of connection state. Allows for ManagedConnection to not leak.
+ disconnected chan struct{}
+ disconnectedm *sync.Once
forcePing chan bool
rawEvents chan json.RawMessage
- wasIntentional bool
- isConnected bool
// UserDetails upon connection
info *Info
@@ -58,32 +56,30 @@ type RTM struct {
connParams url.Values
}
+// signal that we are disconnected by closing the channel.
+// protect it with a mutex to ensure it only happens once.
+func (rtm *RTM) disconnect() {
+ rtm.disconnectedm.Do(func() {
+ close(rtm.disconnected)
+ })
+}
+
// Disconnect and wait, blocking until a successful disconnection.
func (rtm *RTM) Disconnect() error {
- // avoid RTM disconnect race conditions
- rtm.mu.Lock()
- defer rtm.mu.Unlock()
-
- // always push into the disconnected channel when invoked,
+ // always push into the kill channel when invoked,
// this lets the ManagedConnection() function properly clean up.
// if the buffer is full then just continue on.
select {
- case rtm.disconnected <- struct{}{}:
- default:
+ case rtm.killChannel <- true:
+ return nil
+ case <-rtm.disconnected:
+ return ErrAlreadyDisconnected
}
-
- if !rtm.isConnected {
- return errors.New("Invalid call to Disconnect - Slack API is already disconnected")
- }
-
- rtm.killChannel <- true
- return nil
}
// GetInfo returns the info structure received when calling
-// "startrtm", holding all channels, groups and other metadata needed
-// to implement a full chat client. It will be non-nil after a call to
-// StartRTM().
+// "startrtm", holding metadata needed to implement a full
+// chat client. It will be non-nil after a call to StartRTM().
func (rtm *RTM) GetInfo() *Info {
return rtm.info
}