Skip to content

Commit

Permalink
♻️ refactor: updated codebase #14
Browse files Browse the repository at this point in the history
  • Loading branch information
pnguyen215 committed Jan 14, 2024
1 parent 33d8849 commit 1e572c1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
11 changes: 10 additions & 1 deletion pkg/ami/ami.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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():
Expand Down
8 changes: 7 additions & 1 deletion pkg/ami/ami_pub_channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 1e572c1

Please sign in to comment.