当前位置: 首页>>代码示例>>Golang>>正文


Golang Loop.ShallStop方法代码示例

本文整理汇总了Golang中github.com/tideland/golib/loop.Loop.ShallStop方法的典型用法代码示例。如果您正苦于以下问题:Golang Loop.ShallStop方法的具体用法?Golang Loop.ShallStop怎么用?Golang Loop.ShallStop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/tideland/golib/loop.Loop的用法示例。


在下文中一共展示了Loop.ShallStop方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: backendLoop

// backendLoop runs the system monitor.
func (b *stdBackend) backendLoop(l loop.Loop) error {
	// Init the monitor.
	b.init()
	// Run loop.
	for {
		select {
		case <-l.ShallStop():
			return nil
		case measuring := <-b.measuringC:
			// Received a new measuring.
			if mp, ok := b.etmData[measuring.id]; ok {
				mp.update(measuring)
			} else {
				b.etmData[measuring.id] = newStdMeasuringPoint(measuring)
			}
		case ssvChange := <-b.ssvChangeC:
			// Received a new change.
			if ssv, ok := b.ssvData[ssvChange.id]; ok {
				ssv.update(ssvChange)
			} else {
				b.ssvData[ssvChange.id] = newStdStaySetVariable(ssvChange)
			}
		case registration := <-b.retrieverRegistrationC:
			// Received a new retriever for registration.
			b.dsrData[registration.id] = registration.dsr
		case cmd := <-b.commandC:
			// Received a command to process.
			b.processCommand(cmd)
		}
	}
}
开发者ID:postfix,项目名称:golib,代码行数:32,代码来源:standardbackend.go

示例2: backendLoop

// backendLoop is the goroutine for reading, filtering and writing.
func (s *Scroller) backendLoop(l loop.Loop) error {
	// Initial positioning.
	if err := s.seekInitial(); err != nil {
		return err
	}
	// Polling loop.
	timer := time.NewTimer(0)
	for {
		select {
		case <-l.ShallStop():
			return nil
		case <-timer.C:
			for {
				line, readErr := s.readLine()
				_, writeErr := s.writer.Write(line)
				if writeErr != nil {
					return writeErr
				}
				if readErr != nil {
					if readErr != io.EOF {
						return readErr
					}
					break
				}
			}
			if writeErr := s.writer.Flush(); writeErr != nil {
				return writeErr
			}
			timer.Reset(s.pollTime)
		}
	}
}
开发者ID:kung-foo,项目名称:golib,代码行数:33,代码来源:scroller.go

示例3: backendLoop

// backendLoop runs the backend loop of the scene.
func (s *scene) backendLoop(l loop.Loop) (err error) {
	// Defer cleanup.
	defer func() {
		cerr := s.cleanupAllProps()
		if err == nil {
			err = cerr
		}
	}()
	// Init timers.
	var watchdog <-chan time.Time
	var clapperboard <-chan time.Time
	if s.absolute > 0 {
		clapperboard = time.After(s.absolute)
	}
	// Run loop.
	for {
		if s.inactivity > 0 {
			watchdog = time.After(s.inactivity)
		}
		select {
		case <-l.ShallStop():
			return nil
		case timeout := <-watchdog:
			return errors.New(ErrTimeout, errorMessages, "inactivity", timeout)
		case timeout := <-clapperboard:
			return errors.New(ErrTimeout, errorMessages, "absolute", timeout)
		case command := <-s.commandChan:
			s.processCommand(command)
		}
	}
}
开发者ID:kung-foo,项目名称:golib,代码行数:32,代码来源:scene.go

示例4: tickerLoop

// tickerLoop sends ticker events to its own process method.
func (b *tickerBehavior) tickerLoop(l loop.Loop) error {
	for {
		select {
		case <-l.ShallStop():
			return nil
		case now := <-time.After(b.duration):
			// Notify myself, action there to avoid
			// race when subscribers are updated.
			b.ctx.Environment().EmitNew(b.ctx.ID(), TickerTopic, now, nil)
		}
	}
}
开发者ID:kung-foo,项目名称:golib,代码行数:13,代码来源:ticker.go

示例5: backendLoop

// backendLoop manages the scenes and cleans them periodically.
func (m *cookieSceneManager) backendLoop(l loop.Loop) error {
	ticker := time.Tick(5 * time.Minute)
	for {
		select {
		case <-l.ShallStop():
			return nil
		case request := <-m.requestChan:
			m.requestScene(request)
		case <-ticker:
			m.expire()
		}
	}
}
开发者ID:kung-foo,项目名称:golib,代码行数:14,代码来源:tools.go

示例6: publishLoop

func (pa *publicAddress) publishLoop(l loop.Loop) error {
	for {
		select {
		case <-l.ShallStop():
			return nil
		case <-time.After(pa.interval):
			/*
				pa.ctx.EmitNew(SAYS_ALL, cells.PayloadValues{
					"message": fmt.Sprintf("The current time is %v", time.Now().Format(time.RFC850)),
					"from":    PublicAddressUserID,
				}, nil)
			*/
		}
	}
}
开发者ID:kung-foo,项目名称:cellchat,代码行数:15,代码来源:building.go

示例7: backendLoop

// backendLoop processing the changes and the cleanings.
func (m *cacheManager) backendLoop(l loop.Loop) error {
	ticker := time.NewTicker(30 * time.Second)
	for {
		select {
		case <-l.ShallStop():
			return nil
		case c := <-m.changec:
			if c.register {
				m.doRegister(c.value)
			} else {
				m.doUnregister(c.value)
			}
		case <-ticker.C:
			m.doCleaning()
		}
	}
}
开发者ID:kung-foo,项目名称:golib,代码行数:18,代码来源:cache.go

示例8: backendLoop

// backendLoop runs the server backend.
func (c *Crontab) backendLoop(l loop.Loop) error {
	for {
		select {
		case <-l.ShallStop():
			return nil
		case cmd := <-c.commandChan:
			if cmd.add {
				c.jobs[cmd.id] = cmd.job
			} else {
				delete(c.jobs, cmd.id)
			}
		case now := <-c.ticker.C:
			for id, job := range c.jobs {
				c.do(id, job, now)
			}
		}
	}
}
开发者ID:jmptrader,项目名称:golib,代码行数:19,代码来源:timex.go

示例9: backendLoop

// backendLoop is the backend for the processing of messages.
func (c *cell) backendLoop(l loop.Loop) error {
	totalCellsID := identifier.Identifier("cells", c.env.ID(), "total-cells")
	monitoring.IncrVariable(totalCellsID)
	defer monitoring.DecrVariable(totalCellsID)

	for {
		select {
		case <-l.ShallStop():
			return c.behavior.Terminate()
		case event := <-c.eventc:
			if event == nil {
				panic("received illegal nil event!")
			}
			measuring := monitoring.BeginMeasuring(c.measuringID)
			err := c.behavior.ProcessEvent(event)
			measuring.EndMeasuring()
			if err != nil {
				logger.Errorf("cell %q processed event %q with error: %v", c.id, event.Topic(), err)
				return err
			}
		}
	}
}
开发者ID:tideland,项目名称:gocells,代码行数:24,代码来源:cell.go

示例10: backendLoop

// backendLoop is the backend for the processing of messages.
func (c *cell) backendLoop(l loop.Loop) error {
	monitoring.IncrVariable(identifier.Identifier("cells", c.env.ID(), "total-cells"))
	defer monitoring.DecrVariable(identifier.Identifier("cells", c.env.ID(), "total-cells"))

	for {
		select {
		case <-l.ShallStop():
			return c.behavior.Terminate()
		case subscribers := <-c.subscriberc:
			c.subscribers = subscribers
		case event := <-c.eventc:
			if event == nil {
				panic("received illegal nil event!")
			}
			measuring := monitoring.BeginMeasuring(c.measuringID)
			err := c.behavior.ProcessEvent(event)
			if err != nil {
				c.loop.Kill(err)
				continue
			}
			measuring.EndMeasuring()
		}
	}
}
开发者ID:jmptrader,项目名称:golib,代码行数:25,代码来源:cell.go


注:本文中的github.com/tideland/golib/loop.Loop.ShallStop方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。