-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip: support grpc for talking to leader
- Loading branch information
1 parent
1d60ae6
commit de05722
Showing
7 changed files
with
508 additions
and
129 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
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,65 @@ | ||
package hedge | ||
|
||
import ( | ||
"io" | ||
"sync" | ||
|
||
protov1 "github.com/flowerinthenight/hedge/proto/v1" | ||
"google.golang.org/grpc/codes" | ||
"google.golang.org/grpc/status" | ||
) | ||
|
||
type service struct { | ||
op *Op | ||
|
||
protov1.UnimplementedHedgeServer | ||
} | ||
|
||
func (s *service) Send(hs protov1.Hedge_SendServer) error { | ||
ctx := hs.Context() | ||
var w sync.WaitGroup | ||
w.Add(1) | ||
go func() { | ||
defer w.Done() | ||
for { | ||
select { | ||
case <-ctx.Done(): | ||
return | ||
default: | ||
} | ||
|
||
in, err := hs.Recv() | ||
if err == io.EOF { | ||
return | ||
} | ||
|
||
s.op.streamIn <- &StreamMessage{Payload: in} | ||
} | ||
}() | ||
|
||
w.Add(1) | ||
go func() { | ||
defer w.Done() | ||
for { | ||
select { | ||
case <-ctx.Done(): | ||
return | ||
default: | ||
} | ||
|
||
out := <-s.op.streamOut | ||
if out == nil { | ||
return | ||
} | ||
|
||
hs.Send(out.Payload) | ||
} | ||
}() | ||
|
||
w.Wait() | ||
return nil | ||
} | ||
|
||
func (s *service) Broadcast(hs protov1.Hedge_BroadcastServer) error { | ||
return status.Errorf(codes.Unimplemented, "method Broadcast not implemented") | ||
} |
Oops, something went wrong.