forked from juju/juju
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pin.go
39 lines (34 loc) · 819 Bytes
/
pin.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Copyright 2018 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package lease
import (
"github.com/juju/juju/core/lease"
)
// pin is used to deliver lease pinning and unpinning requests to a manager's
// worker loop on behalf of PinLeadership and UnpinLeadership.
type pin struct {
leaseKey lease.Key
entity string
response chan error
stop <-chan struct{}
}
// invoke sends the claim on the supplied channel and waits for a response.
func (c pin) invoke(ch chan<- pin) error {
for {
select {
case <-c.stop:
return errStopped
case ch <- c:
ch = nil
case err := <-c.response:
return err
}
}
}
// respond causes the supplied success value to be sent back to invoke.
func (c pin) respond(err error) {
select {
case <-c.stop:
case c.response <- err:
}
}