Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
9c1758b5
Commit
9c1758b5
authored
Jun 13, 2018
by
bergquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bus: Dispatch now passes empty ctx if handler require it
parent
9ca9a7c3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
10 deletions
+21
-10
pkg/bus/bus.go
+13
-3
pkg/bus/bus_test.go
+8
-7
No files found.
pkg/bus/bus.go
View file @
9c1758b5
...
...
@@ -96,13 +96,23 @@ func (b *InProcBus) DispatchCtx(ctx context.Context, msg Msg) error {
func
(
b
*
InProcBus
)
Dispatch
(
msg
Msg
)
error
{
var
msgName
=
reflect
.
TypeOf
(
msg
)
.
Elem
()
.
Name
()
var
handler
=
b
.
handlers
[
msgName
]
var
handler
=
b
.
handlersWithCtx
[
msgName
]
withCtx
:=
true
if
handler
==
nil
{
withCtx
=
false
handler
=
b
.
handlers
[
msgName
]
}
if
handler
==
nil
{
return
ErrHandlerNotFound
}
var
params
=
make
([]
reflect
.
Value
,
1
)
params
[
0
]
=
reflect
.
ValueOf
(
msg
)
var
params
=
[]
reflect
.
Value
{}
if
withCtx
{
params
=
append
(
params
,
reflect
.
ValueOf
(
context
.
Background
()))
}
params
=
append
(
params
,
reflect
.
ValueOf
(
msg
))
ret
:=
reflect
.
ValueOf
(
handler
)
.
Call
(
params
)
err
:=
ret
[
0
]
.
Interface
()
...
...
pkg/bus/bus_test.go
View file @
9c1758b5
...
...
@@ -34,7 +34,6 @@ func TestDispatchCtxCanUseNormalHandlers(t *testing.T) {
}
bus
.
AddHandler
(
handler
)
bus
.
AddHandlerCtx
(
handlerWithCtx
)
t
.
Run
(
"when a normal handler is registered"
,
func
(
t
*
testing
.
T
)
{
bus
.
Dispatch
(
&
testQuery
{})
...
...
@@ -42,15 +41,17 @@ func TestDispatchCtxCanUseNormalHandlers(t *testing.T) {
if
handlerCallCount
!=
1
{
t
.
Errorf
(
"Expected normal handler to be called 1 time. was called %d"
,
handlerCallCount
)
}
})
t
.
Run
(
"when a ctx handler is registered"
,
func
(
t
*
testing
.
T
)
{
bus
.
DispatchCtx
(
context
.
Background
(),
&
testQuery
{})
t
.
Run
(
"when a ctx handler is registered"
,
func
(
t
*
testing
.
T
)
{
bus
.
AddHandlerCtx
(
handlerWithCtx
)
bus
.
Dispatch
(
&
testQuery
{})
if
handlerWithCtxCallCount
!=
1
{
t
.
Errorf
(
"Expected ctx handler to be called 1 time. was called %d"
,
handlerWithCtxCallCount
)
}
if
handlerWithCtxCallCount
!=
1
{
t
.
Errorf
(
"Expected ctx handler to be called 1 time. was called %d"
,
handlerWithCtxCallCount
)
}
})
})
}
func
TestQueryHandlerReturnsError
(
t
*
testing
.
T
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment