本文整理匯總了Golang中github.com/juju/juju/state.StringsWatcher.Stop方法的典型用法代碼示例。如果您正苦於以下問題:Golang StringsWatcher.Stop方法的具體用法?Golang StringsWatcher.Stop怎麽用?Golang StringsWatcher.Stop使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/juju/juju/state.StringsWatcher
的用法示例。
在下文中一共展示了StringsWatcher.Stop方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: watchAttachments
func (s *StorageProvisionerAPI) watchAttachments(
args params.Entities,
watchEnvironAttachments func() state.StringsWatcher,
watchMachineAttachments func(names.MachineTag) state.StringsWatcher,
parseAttachmentIds func([]string) ([]params.MachineStorageId, error),
) (params.MachineStorageIdsWatchResults, error) {
canAccess, err := s.getScopeAuthFunc()
if err != nil {
return params.MachineStorageIdsWatchResults{}, common.ServerError(common.ErrPerm)
}
results := params.MachineStorageIdsWatchResults{
Results: make([]params.MachineStorageIdsWatchResult, len(args.Entities)),
}
one := func(arg params.Entity) (string, []params.MachineStorageId, error) {
tag, err := names.ParseTag(arg.Tag)
if err != nil || !canAccess(tag) {
return "", nil, common.ErrPerm
}
var w state.StringsWatcher
if tag, ok := tag.(names.MachineTag); ok {
w = watchMachineAttachments(tag)
} else {
w = watchEnvironAttachments()
}
if stringChanges, ok := <-w.Changes(); ok {
changes, err := parseAttachmentIds(stringChanges)
if err != nil {
w.Stop()
return "", nil, err
}
return s.resources.Register(w), changes, nil
}
return "", nil, watcher.EnsureErr(w)
}
for i, arg := range args.Entities {
var result params.MachineStorageIdsWatchResult
id, changes, err := one(arg)
if err != nil {
result.Error = common.ServerError(err)
} else {
result.MachineStorageIdsWatcherId = id
result.Changes = changes
}
results.Results[i] = result
}
return results, nil
}