github.com/juju/juju@v0.0.0-20240430160146-1752b71fcf00/worker/gate/interface.go (about) 1 // Copyright 2015 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package gate 5 6 // Unlocker is used to unlock a shared gate. 7 type Unlocker interface { 8 Unlock() 9 } 10 11 // Waiter is used to wait for a shared gate to be unlocked. 12 type Waiter interface { 13 Unlocked() <-chan struct{} 14 IsUnlocked() bool 15 } 16 17 // Lock combines the Waiter and Unlocker interfaces. 18 type Lock interface { 19 Waiter 20 Unlocker 21 } 22 23 // AlreadyUnlocked is a Waiter that always reports its gate to be unlocked. 24 type AlreadyUnlocked struct{} 25 26 // Unlocked is part of the Waiter interface. 27 func (AlreadyUnlocked) Unlocked() <-chan struct{} { 28 ch := make(chan struct{}) 29 close(ch) 30 return ch 31 } 32 33 // IsUnlocked is part of the Waiter interface. 34 func (AlreadyUnlocked) IsUnlocked() bool { 35 return true 36 }