mirror of
https://github.com/ipfs/kubo.git
synced 2026-03-09 10:18:04 +08:00
Merge pull request #3418 from ipfs/kevina/rmblock-noblock
"block rm": make channel large enough to avoid blocking
This commit is contained in:
commit
e855047ec8
@ -27,7 +27,10 @@ type RmBlocksOpts struct {
|
|||||||
Force bool
|
Force bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func RmBlocks(blocks bs.GCBlockstore, pins pin.Pinner, out chan<- interface{}, cids []*cid.Cid, opts RmBlocksOpts) error {
|
func RmBlocks(blocks bs.GCBlockstore, pins pin.Pinner, cids []*cid.Cid, opts RmBlocksOpts) (<-chan interface{}, error) {
|
||||||
|
// make the channel large enough to hold any result to avoid
|
||||||
|
// blocking while holding the GCLock
|
||||||
|
out := make(chan interface{}, len(cids))
|
||||||
go func() {
|
go func() {
|
||||||
defer close(out)
|
defer close(out)
|
||||||
|
|
||||||
@ -47,7 +50,7 @@ func RmBlocks(blocks bs.GCBlockstore, pins pin.Pinner, out chan<- interface{}, c
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
return nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func FilterPinned(pins pin.Pinner, out chan<- interface{}, cids []*cid.Cid) []*cid.Cid {
|
func FilterPinned(pins pin.Pinner, out chan<- interface{}, cids []*cid.Cid) []*cid.Cid {
|
||||||
|
|||||||
@ -254,8 +254,7 @@ It takes a list of base58 encoded multihashs to remove.
|
|||||||
|
|
||||||
cids = append(cids, c)
|
cids = append(cids, c)
|
||||||
}
|
}
|
||||||
outChan := make(chan interface{})
|
ch, err := util.RmBlocks(n.Blockstore, n.Pinning, cids, util.RmBlocksOpts{
|
||||||
err = util.RmBlocks(n.Blockstore, n.Pinning, outChan, cids, util.RmBlocksOpts{
|
|
||||||
Quiet: quiet,
|
Quiet: quiet,
|
||||||
Force: force,
|
Force: force,
|
||||||
})
|
})
|
||||||
@ -263,7 +262,7 @@ It takes a list of base58 encoded multihashs to remove.
|
|||||||
res.SetError(err, cmds.ErrNormal)
|
res.SetError(err, cmds.ErrNormal)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
res.SetOutput((<-chan interface{})(outChan))
|
res.SetOutput(ch)
|
||||||
},
|
},
|
||||||
PostRun: func(req cmds.Request, res cmds.Response) {
|
PostRun: func(req cmds.Request, res cmds.Response) {
|
||||||
if res.Error() != nil {
|
if res.Error() != nil {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user