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


Golang Set.Sub方法代码示例

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


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

示例1: Generate

// Generate returns and fills a channel with *UnitStateHeartbeat objects. Objects will
// only be returned for units to which this generator is currently subscribed.
func (g *UnitStateGenerator) Generate() (<-chan *UnitStateHeartbeat, error) {
	var lastSubscribed pkg.Set
	if g.lastSubscribed != nil {
		lastSubscribed = g.lastSubscribed.Copy()
	}

	subscribed := g.subscribed.Copy()
	g.lastSubscribed = subscribed

	reportable, err := g.mgr.GetUnitStates(subscribed)
	if err != nil {
		return nil, err
	}

	beatchan := make(chan *UnitStateHeartbeat)
	go func() {
		for name, us := range reportable {
			us := us
			beatchan <- &UnitStateHeartbeat{
				Name:  name,
				State: us,
			}
		}

		if lastSubscribed != nil {
			// For all units that were part of the subscription list
			// last time Generate ran, but are now not part of that
			// list, send nil-State heartbeats to signal removal
			for _, name := range lastSubscribed.Sub(subscribed).Values() {
				beatchan <- &UnitStateHeartbeat{
					Name: name,
				}
			}
		}

		close(beatchan)
	}()

	return beatchan, nil
}
开发者ID:hugoduncan,项目名称:fleet,代码行数:42,代码来源:generator.go


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