Skip to content

Commit

Permalink
Fixed start function in rpc
Browse files Browse the repository at this point in the history
  • Loading branch information
18aaddy committed Sep 22, 2024
1 parent 016f187 commit 88476fa
Showing 1 changed file with 30 additions and 13 deletions.
43 changes: 30 additions & 13 deletions client/rpc.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package client

import (
"context"
"encoding/json"
"fmt"
"github.com/BlocSoc-iitr/selene/common"
Expand Down Expand Up @@ -29,18 +28,36 @@ func (r Rpc) New(node *Node, ip *string, port uint16) Rpc {
Address: address,
}
}
func (r Rpc) Start(ctx context.Context) (string, error) {
rpcInner := RpcInner{
Node: r.Node,
Address: r.Address,
}
handle, addr, err := rpcInner.StartServer()
if err != nil {
return "", err
}
r.Handle = handle
logrus.WithField("target", "selene::rpc").Infof("rpc server started at %s", addr)
return addr, nil

func (r Rpc) Start() (string, error) {
// Create channels to send the address and error back asynchronously
addrChan := make(chan string)
errChan := make(chan error)

// Run the function in a separate goroutine
go func() {
rpcInner := RpcInner{
Node: r.Node,
Address: r.Address,
}
handle, addr, err := rpcInner.StartServer()
if err != nil {
// Send the error on the error channel and close the channels
errChan <- err
close(addrChan)
close(errChan)
return
}
r.Handle = handle
logrus.WithField("target", "selene::rpc").Infof("rpc server started at %s", addr)

// Send the address on the address channel and close the channels
addrChan <- addr
close(addrChan)
close(errChan)
}()

return <-addrChan, <-errChan
}

type RpcInner struct {
Expand Down

0 comments on commit 88476fa

Please sign in to comment.