[手游项目3]-12-Go 语言 select 语句

http://www.runoob.com/go/go-select-statement.html

https://studygolang.com/articles/11186

func (self *Observe) start() {
	if self == nil || self.roomid <= 0 {
		return
	}
	antnet.Go2(func(cstop chan struct{}) {
		obMgr.Store(self.roomid, self)
		defer obMgr.Delete(self.roomid)
		if !self.sendStart() {
			return
		}

		ticker := time.NewTicker(time.Second * 1)
		timeout := time.After(time.Hour * 1)
		sendbuf := bytes.NewBuffer(make([]byte, 1024*16))
		defer func() {
			ticker.Stop()
			self.Over()
			self.sendFrame(sendbuf)
			self.sendOver()
		}()

		for {
			select {
			case <-cstop:
				return
			case <-self.over:
				return
			case <-ticker.C:
				if !self.sendFrame(sendbuf) {
					return
				}
			case <-timeout:
				antnet.LogWarn("ob room:%d is too long", self.roomid)
				return
			}
		}
	})
}

 

你可能感兴趣的:(手游项目3,golang)