github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/worker/lease/claim.go (about) 1 // Copyright 2015 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package lease 5 6 import ( 7 "time" 8 9 "github.com/juju/juju/core/lease" 10 ) 11 12 // claim is used to deliver lease-claim requests to a manager's loop 13 // goroutine on behalf of ClaimLeadership. 14 type claim struct { 15 leaseKey lease.Key 16 holderName string 17 duration time.Duration 18 response chan error 19 stop <-chan struct{} 20 } 21 22 // invoke sends the claim on the supplied channel and waits for a response. 23 func (c claim) invoke(ch chan<- claim) error { 24 for { 25 select { 26 case <-c.stop: 27 return errStopped 28 case ch <- c: 29 ch = nil 30 case err := <-c.response: 31 return err 32 } 33 } 34 } 35 36 // respond causes the supplied success value to be sent back to invoke. 37 func (c claim) respond(err error) { 38 select { 39 case <-c.stop: 40 case c.response <- err: 41 } 42 }