File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 77 "fmt"
88 "io/ioutil"
99 "net/http"
10+ "sync"
1011 "time"
1112
1213 "github.com/go-redis/redis/v8"
2021 hostname * string
2122 password * string
2223 db * int
24+ wg sync.WaitGroup
2325)
2426
2527const (
@@ -84,8 +86,11 @@ func main() {
8486 }
8587
8688 for _ , coin := range coinsData {
87- go Store (rdb , coin , time .Duration (* expiry )* time .Second )
89+ wg .Add (1 )
90+ go Store (& wg , rdb , coin , time .Duration (* expiry )* time .Second )
8891 }
92+ fmt .Println ("waiting for storage" )
93+ wg .Wait ()
8994
9095 pager ++
9196 if pager > * pages {
@@ -134,7 +139,9 @@ func GetMarketData(page int) ([]CoinInfo, error) {
134139}
135140
136141// Store puts the coins values into redis
137- func Store (client * redis.Client , coin CoinInfo , expiry time.Duration ) {
142+ func Store (wg * sync.WaitGroup , client * redis.Client , coin CoinInfo , expiry time.Duration ) {
143+ defer wg .Done ()
144+
138145 client .Set (ctx , coin .ID + "#Symbol" , coin .Symbol , expiry )
139146 client .Set (ctx , coin .ID + "#Name" , coin .Name , expiry )
140147 client .Set (ctx , coin .ID + "#Image" , coin .Image , expiry )
You can’t perform that action at this time.
0 commit comments