github.com/ydb-platform/ydb-go-sdk/v3@v3.57.0/internal/topic/topicreaderinternal/grpc_synced_stream.go (about)

     1  package topicreaderinternal
     2  
     3  import (
     4  	"sync"
     5  
     6  	"github.com/ydb-platform/ydb-go-sdk/v3/internal/grpcwrapper/rawtopic/rawtopicreader"
     7  )
     8  
     9  var _ RawTopicReaderStream = &syncedStream{}
    10  
    11  type syncedStream struct {
    12  	m      sync.Mutex
    13  	stream RawTopicReaderStream
    14  }
    15  
    16  func (s *syncedStream) Recv() (rawtopicreader.ServerMessage, error) {
    17  	// not need synced
    18  	return s.stream.Recv()
    19  }
    20  
    21  func (s *syncedStream) Send(msg rawtopicreader.ClientMessage) error {
    22  	s.m.Lock()
    23  	defer s.m.Unlock()
    24  
    25  	return s.stream.Send(msg)
    26  }
    27  
    28  func (s *syncedStream) CloseSend() error {
    29  	s.m.Lock()
    30  	defer s.m.Unlock()
    31  
    32  	return s.stream.CloseSend()
    33  }