func NewTrackingDispatcher() *TrackingDispatcher {
	return new(TrackingDispatcher)
}
NewTrackingDispatcher creates a new instance of a fake in-memory command.Dispatcher.
package command
import (
	"context"
	"fmt"
	"reflect"
	"sync"
	"github.com/get-eventually/go-eventually"
)
type Dispatcher interface {
	Dispatch(context.Context, eventually.Command) error
}
var _ Dispatcher = InMemoryDispatcher{}
type InMemoryDispatcher struct {
	handlers map[reflect.Type]Handler
}
func NewInMemoryDispatcher() InMemoryDispatcher {
	return InMemoryDispatcher{handlers: make(map[reflect.Type]Handler)}
}
func (d InMemoryDispatcher) Register(handler Handler) {
	typ := reflect.TypeOf(handler.CommandType())
	d.handlers[typ] = handler
}
func (d InMemoryDispatcher) Dispatch(ctx context.Context, cmd eventually.Command) error {
	typ := reflect.TypeOf(cmd.Payload)
	handler, ok := d.handlers[typ]
	if !ok {
		return fmt.Errorf("command.InMemoryDispatcher: no handler registered for type %s", typ.Name())
	}
	if err := handler.Handle(ctx, cmd); err != nil {
		return fmt.Errorf("command.InMemoryDispatcher: failed to execute command: %w", err)
	}
	return nil
}
var _ Dispatcher = &TrackingDispatcher{}
type TrackingDispatcher struct {
	mx               sync.RWMutex
	recordedCommands []eventually.Command
}