Skip to content

Channel magick #266

@Feresey

Description

@Feresey

I noticed a strange work with channels in the file bot.go

func (b *Bot) Start() {
       ...
	stopPoller := make(chan struct{})

	go b.Poller.Poll(b, b.Updates, stopPoller)

	for {
		select {
		case upd := <-b.Updates:
			b.incomingUpdate(&upd)
		case <-b.stop:
			stopPoller <- struct{}{} // why not close?
		case <-stopPoller:                   // read from same channel
			return
		}
	}
}

And how this channel uses in long poller:

func (p *LongPoller) Poll(b *Bot, dest chan Update, stop chan struct{}) {
	go func(stop chan struct{}) {
		<-stop       // read again
		close(stop) // and close???
	}(stop)
        ...
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions