README
¶
dispatch
A powerful read and handle workflow dispatcher for golang.
Install
With a correctly configured Go toolchain:
go get -u github.com/searKing/dispatch
Examples
Let's start registering a couple of URL paths and handlers:
func main() {
var conn chan int
workflow := dispatch.NewDispatcher(
dispatch.ReaderFunc(func() (interface{}, error) {
return ReadMessage(conn)
}),
dispatch.HandlerFunc(func(msg interface{}) error {
m := msg.(*int)
return HandleMessage(m)
}))
workflow.Start()
}
Here we can set the workflow joinable.
workflow := dispatch.NewDispatcher(nil, nil).Joinable()
go workflow.Start()
workflow.Join()
Here we can cancel the workflow.
workflow := dispatch.NewDispatcher(nil, nil).Joinable()
go workflow.Start()
workflow.Context().Done()
workflow.Join()
And this is all you need to know about the basic usage. More advanced options are explained below.
SEE example
License
MIT licensed. See the LICENSE file for details.
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.
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