github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/worker/uniter/hook/listsource.go (about)

     1  // Copyright 2012-2015 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package hook
     5  
     6  type listSource struct {
     7  	NoUpdates
     8  	hooks []Info
     9  }
    10  
    11  // Empty is defined in Source.
    12  func (q *listSource) Empty() bool {
    13  	return len(q.hooks) == 0
    14  }
    15  
    16  // Next is defined in Source.
    17  func (q *listSource) Next() Info {
    18  	if q.Empty() {
    19  		panic("Source is empty")
    20  	}
    21  	return q.hooks[0]
    22  }
    23  
    24  // Pop is defined in Source.
    25  func (q *listSource) Pop() {
    26  	if q.Empty() {
    27  		panic("Source is empty")
    28  	}
    29  	q.hooks = q.hooks[1:]
    30  }
    31  
    32  // NewListSource returns a Source that generates only the supplied hooks, in
    33  // order; and which cannot be updated.
    34  func NewListSource(list []Info) Source {
    35  	source := &listSource{hooks: make([]Info, len(list))}
    36  	copy(source.hooks, list)
    37  	return source
    38  }