resources: Overhaul legacy code around the resource API

This patch makes a number of changes in the engine surrounding the
resource API. In particular:

* Cleanup of send/read event.
* Cleanup of DoSend (now Event) in the Watch method.
* Events are now more consistently pointers.
* Exiting within Watch is now done in a single place.
* Multiple incoming events will be combined into a single action.
* Events in flight during an action are played back after CheckApply.
* Addition of Close method to API

This gets things ready for rate limiting and semaphore metaparams!
This commit is contained in:
James Shubin
2017-01-04 16:22:19 -05:00
parent 74435aac76
commit 51c83116a2
17 changed files with 268 additions and 222 deletions

View File

@@ -46,8 +46,7 @@ type Event struct {
Name EventName
Resp Resp // channel to send an ack response on, nil to skip
//Wg *sync.WaitGroup // receiver barrier to Wait() for everyone else on
Msg string // some words for fun
Activity bool // did something interesting happen?
Err error // store an error in our event
}
// ACK sends a single acknowledgement on the channel if one was requested.
@@ -80,7 +79,7 @@ func NewResp() Resp {
// ACK sends a true value to resp.
func (resp Resp) ACK() {
if resp != nil {
resp <- nil
resp <- nil // TODO: close instead?
}
}
@@ -114,7 +113,7 @@ func (resp Resp) ACKWait() {
}
}
// GetActivity returns the activity value.
func (event *Event) GetActivity() bool {
return event.Activity
// Error returns the stored error value.
func (event *Event) Error() error {
return event.Err
}