Skip to content

Commit

Permalink
Merge pull request #20 from williambailey/midloop
Browse files Browse the repository at this point in the history
Allow declarations, consumers, publishers to be added mid loop
  • Loading branch information
speedywizard authored Dec 6, 2016
2 parents 189fe13 + 4107b72 commit bede840
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,21 @@ func (c *Client) Declare(d []Declaration) {
c.l.Lock()
defer c.l.Unlock()
c.declarations = append(c.declarations, d...)
if ch, err := c.channel(); err == nil {
for _, declare := range d {
declare(ch)
}
}
}

// Consume used to declare consumers
func (c *Client) Consume(cons *Consumer) {
c.l.Lock()
defer c.l.Unlock()
c.consumers[cons] = struct{}{}
if ch, err := c.channel(); err == nil {
go cons.serve(c, ch)
}
}

func (c *Client) deleteConsumer(cons *Consumer) {
Expand All @@ -65,6 +73,9 @@ func (c *Client) Publish(pub *Publisher) {
c.l.Lock()
defer c.l.Unlock()
c.publishers[pub] = struct{}{}
if ch, err := c.channel(); err == nil {
go pub.serve(c, ch)
}
}

func (c *Client) deletePublisher(pub *Publisher) {
Expand Down

0 comments on commit bede840

Please sign in to comment.