Rename AddHandlerCtx to AddHandler (#43557)

This commit is contained in:
idafurjes
2021-12-28 16:08:07 +01:00
committed by GitHub
parent ec9d6b9ca9
commit 7936c4c522
95 changed files with 417 additions and 417 deletions

View File

@@ -37,7 +37,7 @@ type Bus interface {
// callback returns an error.
InTransaction(ctx context.Context, fn func(ctx context.Context) error) error
AddHandlerCtx(handler HandlerFunc)
AddHandler(handler HandlerFunc)
AddEventListenerCtx(handler HandlerFunc)
@@ -114,7 +114,7 @@ func (b *InProcBus) DispatchCtx(ctx context.Context, msg Msg) error {
if withCtx {
params = append(params, reflect.ValueOf(ctx))
} else if setting.Env == setting.Dev {
b.logger.Warn("DispatchCtx called with message handler registered using AddHandler and should be changed to use AddHandlerCtx", "msgName", msgName)
b.logger.Warn("DispatchCtx called with message handler registered using AddHandler and should be changed to use AddHandler", "msgName", msgName)
}
params = append(params, reflect.ValueOf(msg))
@@ -172,7 +172,7 @@ func callListeners(listeners []HandlerFunc, params []reflect.Value) error {
return nil
}
func (b *InProcBus) AddHandlerCtx(handler HandlerFunc) {
func (b *InProcBus) AddHandler(handler HandlerFunc) {
handlerType := reflect.TypeOf(handler)
queryTypeName := handlerType.In(1).Elem().Name()
b.handlersWithCtx[queryTypeName] = handler
@@ -193,10 +193,10 @@ func (b *InProcBus) AddEventListenerCtx(handler HandlerFunc) {
b.listenersWithCtx[eventName] = append(b.listenersWithCtx[eventName], handler)
}
// AddHandlerCtx attaches a handler function to the global bus context.
// AddHandler attaches a handler function to the global bus context.
// Package level function.
func AddHandlerCtx(implName string, handler HandlerFunc) {
globalBus.AddHandlerCtx(handler)
func AddHandler(implName string, handler HandlerFunc) {
globalBus.AddHandler(handler)
}
// AddEventListenerCtx attaches a handler function to the event listener.

View File

@@ -18,7 +18,7 @@ func TestDispatch(t *testing.T) {
var invoked bool
bus.AddHandlerCtx(func(ctx context.Context, query *testQuery) error {
bus.AddHandler(func(ctx context.Context, query *testQuery) error {
invoked = true
return nil
})
@@ -42,7 +42,7 @@ func TestDispatch_ContextHandler(t *testing.T) {
var invoked bool
bus.AddHandlerCtx(func(ctx context.Context, query *testQuery) error {
bus.AddHandler(func(ctx context.Context, query *testQuery) error {
invoked = true
return nil
})
@@ -58,7 +58,7 @@ func TestDispatchCtx(t *testing.T) {
var invoked bool
bus.AddHandlerCtx(func(ctx context.Context, query *testQuery) error {
bus.AddHandler(func(ctx context.Context, query *testQuery) error {
invoked = true
return nil
})
@@ -74,7 +74,7 @@ func TestDispatchCtx_NoContextHandler(t *testing.T) {
var invoked bool
bus.AddHandlerCtx(func(ctx context.Context, query *testQuery) error {
bus.AddHandler(func(ctx context.Context, query *testQuery) error {
invoked = true
return nil
})
@@ -98,7 +98,7 @@ func TestQuery(t *testing.T) {
want := "hello from handler"
bus.AddHandlerCtx(func(ctx context.Context, q *testQuery) error {
bus.AddHandler(func(ctx context.Context, q *testQuery) error {
q.Resp = want
return nil
})
@@ -114,7 +114,7 @@ func TestQuery(t *testing.T) {
func TestQuery_HandlerReturnsError(t *testing.T) {
bus := New()
bus.AddHandlerCtx(func(ctx context.Context, query *testQuery) error {
bus.AddHandler(func(ctx context.Context, query *testQuery) error {
return errors.New("handler error")
})