Skip to content

Commit

Permalink
- Added: bus handler example test
Browse files Browse the repository at this point in the history
  • Loading branch information
donutloop committed Sep 30, 2017
1 parent 6519955 commit 2967877
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion bus/doc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

// Creates a bus and adds a listener to a message afterward it publishes a new message
func ExampleBus() {
func ExampleBusListener() {

type msg struct {
Id int64
Expand All @@ -26,3 +26,25 @@ func ExampleBus() {

// Output: db insert listener
}

// Creates a bus and adds a handler for a message afterward it dispatch a new message
func ExampleBusHandler() {

type msg struct {
Id int64
body string
}

b := bus.New()

b.AddHandler(func(m *msg) error {
fmt.Println("db insert listener")
return nil
})

if err := b.Dispatch(new(msg)); err != nil {
fmt.Println(fmt.Sprintf("bus: %v", err))
}

// Output: db insert listener
}

0 comments on commit 2967877

Please sign in to comment.