diff options
author | Wim <wim@42.be> | 2021-10-17 00:47:22 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-17 00:47:22 +0200 |
commit | 4dd8bae5c91fa4aef09d865d8fef1acd84f90925 (patch) | |
tree | ffad9b242daccaf8c86d1c1fbd59032302bd3be9 /vendor/github.com/gopackage/ddp/utils.go | |
parent | 7ae45c42e712bd0e66c101f3f714c05aa1dc2104 (diff) | |
download | matterbridge-msglm-4dd8bae5c91fa4aef09d865d8fef1acd84f90925.tar.gz matterbridge-msglm-4dd8bae5c91fa4aef09d865d8fef1acd84f90925.tar.bz2 matterbridge-msglm-4dd8bae5c91fa4aef09d865d8fef1acd84f90925.zip |
Update dependencies (#1610)
* Update dependencies
* Update module to go 1.17
Diffstat (limited to 'vendor/github.com/gopackage/ddp/utils.go')
-rw-r--r-- | vendor/github.com/gopackage/ddp/utils.go | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/vendor/github.com/gopackage/ddp/utils.go b/vendor/github.com/gopackage/ddp/utils.go new file mode 100644 index 00000000..7ff16a20 --- /dev/null +++ b/vendor/github.com/gopackage/ddp/utils.go @@ -0,0 +1,77 @@ +package ddp + +import ( + "fmt" + "sync" + "time" + + "github.com/apex/log" +) + +// Contains common utility types. + +// ------------------------------------------------------------------- + +// KeyManager provides simple incrementing IDs for ddp messages. +type KeyManager struct { + // nextID is the next ID for API calls + nextID uint64 + // idMutex is a mutex to protect ID updates + idMutex *sync.Mutex +} + +// NewKeyManager creates a new instance and sets up resources. +func NewKeyManager() *KeyManager { + return &KeyManager{idMutex: new(sync.Mutex)} +} + +// Next issues a new ID for use in calls. +func (id *KeyManager) Next() string { + id.idMutex.Lock() + next := id.nextID + id.nextID++ + id.idMutex.Unlock() + return fmt.Sprintf("%x", next) +} + +// ------------------------------------------------------------------- + +// PingTracker tracks in-flight pings. +type PingTracker struct { + handler func(error) + timeout time.Duration + timer *time.Timer +} + +// ------------------------------------------------------------------- + +// Call represents an active RPC call. +type Call struct { + ID string // The uuid for this method call + ServiceMethod string // The name of the service and method to call. + Args interface{} // The argument to the function (*struct). + Reply interface{} // The reply from the function (*struct). + Error error // After completion, the error status. + Done chan *Call // Strobes when call is complete. + Owner *Client // Client that owns the method call +} + +// done removes the call from any owners and strobes the done channel with itself. +func (call *Call) done() { + delete(call.Owner.calls, call.ID) + select { + case call.Done <- call: + // ok + default: + // We don't want to block here. It is the caller's responsibility to make + // sure the channel has enough buffer space. See comment in Go(). + log.Debug("rpc: discarding Call reply due to insufficient Done chan capacity") + } +} + +// IgnoreErr logs an error if it occurs and ignores it. +func IgnoreErr(err error, msg string) { + if err != nil { + log.WithError(err).Debug(msg) + } +}
\ No newline at end of file |