github.com/anycable/anycable-go@v1.5.1/node/disconnector.go (about) 1 package node 2 3 import ( 4 "context" 5 ) 6 7 // Disconnector is an interface for disconnect queue implementation 8 type Disconnector interface { 9 Run() error 10 Shutdown(ctx context.Context) error 11 Enqueue(*Session) error 12 Size() int 13 } 14 15 // NoopDisconnectQueue is non-operational disconnect queue implementation 16 type NoopDisconnectQueue struct{} 17 18 // Run does nothing 19 func (d *NoopDisconnectQueue) Run() error { 20 return nil 21 } 22 23 // Shutdown does nothing 24 func (d *NoopDisconnectQueue) Shutdown(ctx context.Context) error { 25 return nil 26 } 27 28 // Size returns 0 29 func (d *NoopDisconnectQueue) Size() int { 30 return 0 31 } 32 33 // Enqueue does nothing 34 func (d *NoopDisconnectQueue) Enqueue(s *Session) error { 35 return nil 36 } 37 38 // NewNoopDisconnector returns new NoopDisconnectQueue 39 func NewNoopDisconnector() *NoopDisconnectQueue { 40 return &NoopDisconnectQueue{} 41 } 42 43 // InlineDisconnector performs Disconnect calls synchronously 44 type InlineDisconnector struct { 45 n *Node 46 } 47 48 // Run does nothing 49 func (d *InlineDisconnector) Run() error { 50 return nil 51 } 52 53 // Shutdown does nothing 54 func (d *InlineDisconnector) Shutdown(ctx context.Context) error { 55 return nil 56 } 57 58 // Size returns 0 59 func (d *InlineDisconnector) Size() int { 60 return 0 61 } 62 63 // Enqueue disconnects session immediately 64 func (d *InlineDisconnector) Enqueue(s *Session) error { 65 return d.n.DisconnectNow(s) 66 } 67 68 // NewInlineDisconnector returns new InlineDisconnector 69 func NewInlineDisconnector(n *Node) *InlineDisconnector { 70 return &InlineDisconnector{n: n} 71 }