Skip to content

Commit

Permalink
rename concurrent map. add more todos for error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
illia-malachyn committed Nov 14, 2024
1 parent b30d63d commit 839c35c
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions engine/access/rest/websockets/data_provider/blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,40 @@ import (

type MockBlockProvider struct {
id uuid.UUID
ch chan<- interface{}
topicChan chan<- interface{} // provider is not the one who is responsible to close this channel
topic string
logger zerolog.Logger
ctx context.Context
stopProviderFunc context.CancelFunc
streamApi state_stream.API
}

func NewMockBlockProvider(
ctx context.Context,
ch chan<- interface{},
topic string,
logger zerolog.Logger,
streamApi state_stream.API,
) *MockBlockProvider {
ctx, cancel := context.WithCancel(ctx)
return &MockBlockProvider{
id: uuid.New(),
ch: ch,
topicChan: ch,
topic: topic,
logger: logger.With().Str("component", "block-provider").Logger(),
ctx: ctx,
stopProviderFunc: cancel,
stopProviderFunc: nil,
streamApi: streamApi,
}
}

func (p *MockBlockProvider) Run(_ context.Context) {
select {
case <-p.ctx.Done():
return
default:
p.ch <- "hello world"
func (p *MockBlockProvider) Run(ctx context.Context) {
ctx, cancel := context.WithCancel(ctx)
p.stopProviderFunc = cancel

for {
select {
case <-ctx.Done():
return
case p.topicChan <- "hello world":
return
}
}
}

Expand Down

0 comments on commit 839c35c

Please sign in to comment.