本文整理匯總了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
}