github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/worker/gate/interface.go (about)

     1  // Copyright 2015 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  // package gate provides a mechanism by which independent workers can wait for
     5  // one another to finish a task, without introducing explicit dependencies
     6  // between those workers.
     7  package gate
     8  
     9  // Unlocker is used to unlock a shared gate.
    10  type Unlocker interface {
    11  	Unlock()
    12  }
    13  
    14  // Waiter is used to wait for a shared gate to be unlocked.
    15  type Waiter interface {
    16  	Unlocked() <-chan struct{}
    17  	IsUnlocked() bool
    18  }
    19  
    20  // Lock combines the Waiter and Unlocker interfaces.
    21  type Lock interface {
    22  	Waiter
    23  	Unlocker
    24  }
    25  
    26  // AlreadyUnlocked is a Waiter that always reports its gate to be unlocked.
    27  type AlreadyUnlocked struct{}
    28  
    29  // Unlocked is part of the Waiter interface.
    30  func (AlreadyUnlocked) Unlocked() <-chan struct{} {
    31  	ch := make(chan struct{})
    32  	close(ch)
    33  	return ch
    34  }
    35  
    36  // IsUnlocked is part of the Waiter interface.
    37  func (AlreadyUnlocked) IsUnlocked() bool {
    38  	return true
    39  }