github.com/mattyr/nomad@v0.3.3-0.20160919021406-3485a065154a/nomad/watch/watch.go (about)

     1  package watch
     2  
     3  // The watch package provides a means of describing a watch for a blocking
     4  // query. It is exported so it may be shared between Nomad's RPC layer and
     5  // the underlying state store.
     6  
     7  // Item describes the scope of a watch. It is used to provide a uniform
     8  // input for subscribe/unsubscribe and notification firing. Specifying
     9  // multiple fields does not place a watch on multiple items. Each Item
    10  // describes exactly one scoped watch.
    11  type Item struct {
    12  	Alloc      string
    13  	AllocEval  string
    14  	AllocJob   string
    15  	AllocNode  string
    16  	Eval       string
    17  	Job        string
    18  	JobSummary string
    19  	Node       string
    20  	Table      string
    21  }
    22  
    23  // Items is a helper used to construct a set of watchItems. It deduplicates
    24  // the items as they are added using map keys.
    25  type Items map[Item]struct{}
    26  
    27  // NewItems creates a new Items set and adds the given items.
    28  func NewItems(items ...Item) Items {
    29  	wi := make(Items)
    30  	for _, item := range items {
    31  		wi.Add(item)
    32  	}
    33  	return wi
    34  }
    35  
    36  // Add adds an item to the watch set.
    37  func (wi Items) Add(i Item) {
    38  	wi[i] = struct{}{}
    39  }