Documentation ¶
Index ¶
- type ChanDispatch
- type Dispatch
- func (d *Dispatch) AllowHandleInGroutine() bool
- func (d *Dispatch) Context() context.Context
- func (d *Dispatch) GetHandleGoroutine() bool
- func (d *Dispatch) Handle(msg interface{}) error
- func (d *Dispatch) Join() *Dispatch
- func (d *Dispatch) Joinable() *Dispatch
- func (d *Dispatch) PutHandleGoroutine()
- func (d *Dispatch) Read() (interface{}, error)
- func (d *Dispatch) Start() *Dispatch
- func (d *Dispatch) UnJoinable() *Dispatch
- func (d *Dispatch) WithContext(ctx context.Context) *Dispatch
- type Handler
- type HandlerFunc
- type Reader
- type ReaderFunc
- type WaitGroup
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ChanDispatch ¶
type ChanDispatch struct { *Dispatch // contains filtered or unexported fields }
func NewChanDispatch ¶
func NewChanDispatch(handler Handler, concurrentReadMax int) *ChanDispatch
func NewChanDispatch3 ¶
func NewChanDispatch3(handler Handler, concurrentReadMax int, concurrentHandleMax int) *ChanDispatch
func (*ChanDispatch) SendMessage ¶
func (thiz *ChanDispatch) SendMessage(message interface{}) bool
type Dispatch ¶
type Dispatch struct {
// contains filtered or unexported fields
}
Dispatch is a middleman between the Reader and Processor.
Example ¶
package main import ( "context" "errors" "log" "github.com/searKing/golang/go/x/dispatch" ) type DispatchMsg struct { data int } func main() { var conn chan DispatchMsg dispatch.NewDispatch( dispatch.ReaderFunc(func(ctx context.Context) (interface{}, error) { return ReadMessage(conn) }), dispatch.HandlerFunc(func(ctx context.Context, msg interface{}) error { m := msg.(*DispatchMsg) return HandleMessage(m) })).Start() } func ReadMessage(c <-chan DispatchMsg) (interface{}, error) { var msg DispatchMsg var ok bool if msg, ok = <-c; ok { log.Println("Recv From Channel Failed") return nil, errors.New("recv from channel failed") } log.Printf("Recv From Channel Success: %v\n", msg.data) return &msg, nil } // just print what's received func HandleMessage(msg *DispatchMsg) error { if msg == nil { log.Println("Handle From Channel Failed") return errors.New("handle from channel failed") } log.Printf("Handle From Channel Success: %v\n", msg.data) return nil }
Output:
func NewDispatch ¶
func (*Dispatch) AllowHandleInGroutine ¶
func (*Dispatch) GetHandleGoroutine ¶
func (*Dispatch) Joinable ¶
make Dispatch joinable Join() blocks until all recv and handle workflows started after Join() is finished RECOMMECD : call Joinable() before Start() to join all workflows
func (*Dispatch) PutHandleGoroutine ¶
func (d *Dispatch) PutHandleGoroutine()
func (*Dispatch) UnJoinable ¶
make Dispatch unjoinable, as Join() return immediately when called
type HandlerFunc ¶
type ReaderFunc ¶
Click to show internal directories.
Click to hide internal directories.