-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from stanipetrosyan/refactor-topic
Refactor topic
- Loading branch information
Showing
9 changed files
with
225 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package goeventbus | ||
|
||
type Context interface { | ||
Result() Message | ||
} | ||
|
||
type ConsumerContext struct { | ||
Ch chan Message | ||
message Message | ||
} | ||
|
||
func (d *ConsumerContext) Reply(data any) { | ||
d.Ch <- Message{Data: data} | ||
} | ||
|
||
func (d *ConsumerContext) Result() Message { | ||
return d.message | ||
} | ||
|
||
func (d *ConsumerContext) Handle(consume func(message Message)) { | ||
go func(ch chan Message) { | ||
for data := range ch { | ||
consume(data) | ||
} | ||
}(d.Ch) | ||
} | ||
|
||
func (d ConsumerContext) SetData(msg Message) ConsumerContext { | ||
d.message = msg | ||
return d | ||
} | ||
|
||
func NewConsumerContext(ch chan Message) ConsumerContext { | ||
return ConsumerContext{Ch: ch} | ||
} | ||
|
||
type InterceptorContext struct { | ||
message Message | ||
topic *Topic | ||
} | ||
|
||
func (d *InterceptorContext) Next() { | ||
for _, item := range d.topic.GetChannels() { | ||
item <- d.message | ||
} | ||
} | ||
|
||
func (d *InterceptorContext) Result() Message { | ||
return d.message | ||
} | ||
|
||
func (d InterceptorContext) SetData(msg Message) InterceptorContext { | ||
d.message = msg | ||
return d | ||
} | ||
|
||
func NewInterceptorContext(topic *Topic) InterceptorContext { | ||
return InterceptorContext{topic: topic} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.