refactor: don't use a buffered chan

This commit is contained in:
Derrick Hammer 2024-03-01 05:14:47 -05:00
parent b46e12b972
commit d5e2770135
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 15 additions and 15 deletions

View File

@ -875,7 +875,8 @@ func (s *S5API) accountPinManifest(jc jape.Context, userId uint, cid *encoding.C
q := queue.NewPool(10)
defer q.Release()
rets := make(chan pinQueueResult, len(cids))
rets := make(chan pinQueueResult)
defer close(rets)
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() {
q.Wait()
close(rets)
for ret := range 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 {
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,
}
}
q.Wait()
jc.Encode(&results)
}