mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-08-31 13:04:02 +03:00
Implement caching dns resolver
This commit is contained in:
@@ -9,13 +9,13 @@ import (
|
||||
"github.com/OneOfOne/xxhash"
|
||||
)
|
||||
|
||||
type eventStream struct {
|
||||
type EventStream struct {
|
||||
ctx context.Context
|
||||
ctxCancel context.CancelFunc
|
||||
chans []chan mtglib.Event
|
||||
}
|
||||
|
||||
func (e eventStream) Send(ctx context.Context, evt mtglib.Event) {
|
||||
func (e EventStream) Send(ctx context.Context, evt mtglib.Event) {
|
||||
var chanNo uint32
|
||||
|
||||
if streamID := evt.StreamID(); streamID != "" {
|
||||
@@ -31,17 +31,17 @@ func (e eventStream) Send(ctx context.Context, evt mtglib.Event) {
|
||||
}
|
||||
}
|
||||
|
||||
func (e eventStream) Shutdown() {
|
||||
func (e EventStream) Shutdown() {
|
||||
e.ctxCancel()
|
||||
}
|
||||
|
||||
func NewEventStream(observerFactories []ObserverFactory) mtglib.EventStream {
|
||||
func NewEventStream(observerFactories []ObserverFactory) EventStream {
|
||||
if len(observerFactories) == 0 {
|
||||
observerFactories = append(observerFactories, NewNoopObserver)
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
rv := eventStream{
|
||||
rv := EventStream{
|
||||
ctx: ctx,
|
||||
ctxCancel: cancel,
|
||||
chans: make([]chan mtglib.Event, runtime.NumCPU()),
|
||||
|
||||
@@ -19,7 +19,7 @@ type EventStreamTestSuite struct {
|
||||
ctxCancel context.CancelFunc
|
||||
observerMock1 *ObserverMock
|
||||
observerMock2 *ObserverMock
|
||||
stream mtglib.EventStream
|
||||
stream events.EventStream
|
||||
}
|
||||
|
||||
func (suite *EventStreamTestSuite) SetupTest() {
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
type noop struct{}
|
||||
|
||||
func (n noop) Send(ctx context.Context, evt mtglib.Event) {}
|
||||
func (n noop) Shutdown() {}
|
||||
|
||||
func NewNoopStream() mtglib.EventStream {
|
||||
return noop{}
|
||||
|
||||
@@ -70,8 +70,6 @@ func (suite *NoopTestSuite) TestStream() {
|
||||
stream.Send(suite.ctx, value)
|
||||
})
|
||||
}
|
||||
|
||||
stream.Shutdown()
|
||||
}
|
||||
|
||||
func (suite *NoopTestSuite) TestObserver() {
|
||||
|
||||
Reference in New Issue
Block a user