github.com/searKing/golang/go@v1.2.117/x/dispatch/readme.md (about)

     1  # dispatch
     2  
     3  A powerful read and handle workflow dispatcher for golang.
     4  
     5  * [Install](#install)
     6  * [Examples](#examples)
     7  
     8  ---
     9  
    10  ## Install
    11  
    12  With a [correctly configured](https://golang.org/doc/install#testing) Go toolchain:
    13  
    14  ```sh
    15  go get -u github.com/searKing/dispatch
    16  ```
    17  
    18  ---
    19  
    20  ## Examples
    21  
    22  Let's start registering a couple of URL paths and handlers:
    23  
    24  ```go
    25  func main() {
    26      var conn chan int
    27      workflow := dispatch.NewDispatcher(
    28      	dispatch.ReaderFunc(func() (interface{}, error) {
    29      		return ReadMessage(conn)
    30      	}), 
    31      	dispatch.HandlerFunc(func(msg interface{}) error {
    32      		m := msg.(*int)
    33      		return HandleMessage(m)
    34      	}))
    35      workflow.Start()
    36  }
    37  ```
    38  
    39  Here we can set the workflow joinable. 
    40  ```go
    41      workflow := dispatch.NewDispatcher(nil, nil).Joinable()
    42      go workflow.Start()
    43      workflow.Join()
    44  ```
    45  
    46  Here we can cancel the workflow. 
    47  
    48  ```go
    49      workflow := dispatch.NewDispatcher(nil, nil).Joinable()
    50      go workflow.Start()
    51  	workflow.Context().Done()
    52  	workflow.Join()
    53  ```
    54  
    55  And this is all you need to know about the basic usage. More advanced options are explained below.
    56  
    57  SEE [example](https://github.com/searKing/dispatch/tree/master/example_test.go)
    58  
    59  ---
    60  
    61  ## License
    62  
    63  MIT licensed. See the LICENSE file for details.