diff --git a/pkg/ami/ami.go b/pkg/ami/ami.go index 958b904..895d188 100644 --- a/pkg/ami/ami.go +++ b/pkg/ami/ami.go @@ -37,6 +37,15 @@ func (c *AMI) Context() context.Context { return c.ctx } +func (c *AMI) SetSubs(value *AMIPubSubQueue) *AMI { + c.subs = value + return c +} + +func (c *AMI) Subs() *AMIPubSubQueue { + return c.subs +} + // Action sends an AMI action message to the Asterisk server. // If the action message does not have an ActionID, it adds one automatically. // The method returns true if the action message is successfully sent, otherwise false. @@ -298,7 +307,7 @@ func (c *AMI) release(ctx context.Context) { c.subs = NewPubSubQueue() c.err = make(chan error) go func() { - defer c.subs.Disabled() + defer c.subs.TurnOff() for { select { case <-ctx.Done(): diff --git a/pkg/ami/ami_pub_channel.go b/pkg/ami/ami_pub_channel.go index 81f4a6c..dda34dd 100644 --- a/pkg/ami/ami_pub_channel.go +++ b/pkg/ami/ami_pub_channel.go @@ -13,12 +13,18 @@ func NewPubSubQueue() *AMIPubSubQueue { return c } -func (k *AMIPubSubQueue) Disabled() { +func (k *AMIPubSubQueue) TurnOff() { k.mutex.Lock() defer k.mutex.Unlock() k.Off = true } +func (k *AMIPubSubQueue) TurnOn() { + k.mutex.Lock() + defer k.mutex.Unlock() + k.Off = false +} + func (k *AMIPubSubQueue) Destroy() { k.mutex.Lock() defer k.mutex.Unlock()