forked from akash-network/node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
monitor.go
43 lines (35 loc) · 922 Bytes
/
monitor.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package common
import (
"context"
"github.com/ovrclk/akash/marketplace"
"github.com/tendermint/tendermint/libs/log"
tmclient "github.com/tendermint/tendermint/rpc/client"
)
func MonitorMarketplace(ctx context.Context, log log.Logger, client *tmclient.HTTP, handler marketplace.Handler) error {
ctx, cancel := context.WithCancel(ctx)
if err := client.Start(); err != nil {
log.Error("error starting ws client", "error", err)
cancel()
return err
}
cdonech := make(chan interface{})
defer func() { <-cdonech }()
go func() {
defer close(cdonech)
client.Wait()
}()
monitor, err := marketplace.NewMonitor(ctx, log, client, "akash-cli", handler, marketplace.TxQuery())
if err != nil {
cancel()
return err
}
defer func() { <-monitor.Wait() }()
select {
case <-ctx.Done():
client.UnsubscribeAll(context.Background(), "akash-cli")
client.Stop()
case <-cdonech:
}
cancel()
return nil
}