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
|
package hub
import "sync"
// Hub acts as the messaging hub between components -- that is,
// it controls how the communication that goes through channels
// are handled.
type Hub struct {
isSync bool
mutex sync.Mutex
queryCh chan Payload
drawCh chan Payload
statusMsgCh chan Payload
pagingCh chan Payload
}
// Payload is a wrapper around the actual request value that needs
// to be passed. It contains an optional channel field which can
// be filled to force synchronous communication between the
// sender and receiver
type Payload interface {
// Batch returns true if this payload is part of a batch operation.
Batch() bool
// Data allows you to retrieve the data that's embedded in the payload.
Data() interface{}
// Done is called when the payload has been processed. There are cases
// where the payload processing is expected to be synchronized with the
// caller, and this method signals the caller that it is safe to proceed
// to whatever next action it was expecting
Done()
}
type payload struct {
batch bool
data interface{}
done chan struct{}
}
|