refactor: don't use a buffered chan
This commit is contained in:
parent
b46e12b972
commit
d5e2770135
30
api/s5/s5.go
30
api/s5/s5.go
|
@ -875,7 +875,8 @@ func (s *S5API) accountPinManifest(jc jape.Context, userId uint, cid *encoding.C
|
||||||
|
|
||||||
q := queue.NewPool(10)
|
q := queue.NewPool(10)
|
||||||
defer q.Release()
|
defer q.Release()
|
||||||
rets := make(chan pinQueueResult, len(cids))
|
rets := make(chan pinQueueResult)
|
||||||
|
defer close(rets)
|
||||||
|
|
||||||
results := make(map[string]pinResult, len(cids))
|
results := make(map[string]pinResult, len(cids))
|
||||||
|
|
||||||
|
@ -909,22 +910,21 @@ func (s *S5API) accountPinManifest(jc jape.Context, userId uint, cid *encoding.C
|
||||||
}
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
q.Wait()
|
for ret := range rets {
|
||||||
close(rets)
|
b64, err := ret.cid.ToBase64Url()
|
||||||
|
if err != nil {
|
||||||
|
s.logger.Error("Error encoding CID to base64", zap.Error(err))
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
results[b64] = pinResult{
|
||||||
|
success: ret.success,
|
||||||
|
error: ret.error,
|
||||||
|
}
|
||||||
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
for ret := range rets {
|
q.Wait()
|
||||||
b64, err := ret.cid.ToBase64Url()
|
|
||||||
if err != nil {
|
|
||||||
s.logger.Error("Error encoding CID to base64", zap.Error(err))
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
results[b64] = pinResult{
|
|
||||||
success: ret.success,
|
|
||||||
error: ret.error,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
jc.Encode(&results)
|
jc.Encode(&results)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue