diff options
| author | mo khan <mo@mokhan.ca> | 2025-07-24 12:32:51 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2025-07-24 12:32:51 -0600 |
| commit | c089c3f34e367692879826859bda839ef233a1b1 (patch) | |
| tree | 787c4a816f58ed7693812e3f0537b2456cb737c3 | |
| parent | 2ea19d01b148082f75609ca25646f2aeb3682fe2 (diff) | |
refactor: rename ctor function
| -rw-r--r-- | pkg/event/typed_aggregator.go | 8 | ||||
| -rw-r--r-- | pkg/event/typed_aggregator_test.go | 6 |
2 files changed, 9 insertions, 5 deletions
diff --git a/pkg/event/typed_aggregator.go b/pkg/event/typed_aggregator.go index 5a0c9f4..c788756 100644 --- a/pkg/event/typed_aggregator.go +++ b/pkg/event/typed_aggregator.go @@ -4,9 +4,13 @@ type TypedAggregator[T any] struct { aggregator *Aggregator } -func NewTypedAggregator[T any]() *TypedAggregator[T] { +func NewAggregator[T any]() *TypedAggregator[T] { + return NewWith[T](New()) +} + +func NewWith[T any](aggregator *Aggregator) *TypedAggregator[T] { return &TypedAggregator[T]{ - aggregator: New(), + aggregator: aggregator, } } diff --git a/pkg/event/typed_aggregator_test.go b/pkg/event/typed_aggregator_test.go index 2aedd99..259c172 100644 --- a/pkg/event/typed_aggregator_test.go +++ b/pkg/event/typed_aggregator_test.go @@ -13,7 +13,7 @@ func TestTypedAggregator(t *testing.T) { t.Run("Publish", func(t *testing.T) { t.Run("without any subscribers", func(t *testing.T) { - aggregator := NewTypedAggregator[announcement]() + aggregator := NewAggregator[announcement]() aggregator.Publish("announcement", announcement{ message: "Business, Business, Business... Numbers!", @@ -22,7 +22,7 @@ func TestTypedAggregator(t *testing.T) { t.Run("with a single subscription", func(t *testing.T) { called := false - aggregator := NewTypedAggregator[announcement]() + aggregator := NewAggregator[announcement]() aggregator.SubscribeTo("announcement", func(payload announcement) { called = true @@ -35,7 +35,7 @@ func TestTypedAggregator(t *testing.T) { }) t.Run("with multiple subscribers", func(t *testing.T) { - aggregator := NewTypedAggregator[announcement]() + aggregator := NewAggregator[announcement]() called := map[int]bool{} aggregator.SubscribeTo("announcement", func(payload announcement) { |
