Skip to content

Commit

Permalink
feat: allow send & subscribe symulnateously
Browse files Browse the repository at this point in the history
  • Loading branch information
amimart committed Aug 10, 2022
1 parent 99634d8 commit 8fece85
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
5 changes: 2 additions & 3 deletions graph/schema.resolvers.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,13 @@ func (r *subscriptionResolver) Send(ctx context.Context, input model.SendInput)
return nil, err
}

if err := r.Faucet.Send(input.ToAddress); err != nil {
rawTxResponseChan, err := r.Faucet.Subscribe(input.ToAddress)
if err != nil {
log.Err(err).Str("toAddress", input.ToAddress).Msg("Could not register send request")
return nil, err
}

log.Info().Str("toAddress", input.ToAddress).Msg("Register send request")

rawTxResponseChan := r.Faucet.Subscribe()
txResponseChan := make(chan *model.TxResponse)
go func() {
for rawTx := range rawTxResponseChan {
Expand Down
9 changes: 6 additions & 3 deletions pkg/client/faucet.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type Faucet interface {
GetFromAddr() types.AccAddress
SubmitTx(ctx context.Context) (*types.TxResponse, error)
Send(addr string) error
Subscribe() <-chan *types.TxResponse
Subscribe(addr string) (<-chan *types.TxResponse, error)
Close() error
}

Expand Down Expand Up @@ -163,11 +163,14 @@ func (f *faucet) Send(addr string) error {
return nil
}

func (f *faucet) Subscribe() <-chan *types.TxResponse {
func (f *faucet) Subscribe(addr string) (<-chan *types.TxResponse, error) {
if err := f.Send(addr); err != nil {
return nil, err
}
txResponseChan := make(chan *types.TxResponse)
f.txResponseChans = append(f.txResponseChans, txResponseChan)

return txResponseChan
return txResponseChan, nil
}

func (f *faucet) Close() error {
Expand Down

0 comments on commit 8fece85

Please sign in to comment.