Skip to content

Commit

Permalink
reverted pin ls all commands to be synchronous. The PinLsAll coreapi …
Browse files Browse the repository at this point in the history
…function no long returns nil to the error channel if there are no errors.
  • Loading branch information
aschmahmann committed Oct 16, 2019
1 parent 2de82d6 commit 219cf2d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 50 deletions.
49 changes: 20 additions & 29 deletions core/commands/pin.go
Original file line number Diff line number Diff line change
Expand Up @@ -487,39 +487,30 @@ func pinLsAll(req *cmds.Request, typeStr string, pinning pin.Pinner, dag ipld.DA

procErr := make(chan error, 1)
ctx := req.Context
go func() {
for {
select {
case p, ok := <-pinCh:
if !ok {
procErr <- nil
return
}
if err := emit(&PinLsOutputWrapper{
PinLsObject: PinLsObject{
Type: p.Type(),
Cid: enc.Encode(p.Path().Cid()),
},
}); err != nil {
procErr <- err
return
}
for {
select {
case p, ok := <-pinCh:
if !ok {
procErr <- nil
return nil
}
if err := emit(&PinLsOutputWrapper{
PinLsObject: PinLsObject{
Type: p.Type(),
Cid: enc.Encode(p.Path().Cid()),
},
}); err != nil {
return err
}

case <-ctx.Done():
procErr <- ctx.Err()
return
case <-ctx.Done():
return ctx.Err()
case err := <-errCh:
if err != nil {
return err
}
}
}()

if err := <-errCh; err != nil {
return err
}
if err := <-procErr; err != nil {
return err
}

return nil
}

const (
Expand Down
34 changes: 13 additions & 21 deletions core/coreapi/pin.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,28 +195,21 @@ func (api *PinAPI) pinLsAll(typeStr string, ctx context.Context) ([]coreiface.Pi
pinCh, errCh := PinLsAll(ctx, typeStr, api.pinning, api.dag)

var pins []coreiface.Pin
ctxError := make(chan error, 1)
go func() {
for {
select {
case p, ok := <-pinCh:
if !ok {
ctxError <- nil
return
}
pins = append(pins, p)
case <-ctx.Done():
ctxError <- ctx.Err()
return
loop:
for {
select {
case p, ok := <-pinCh:
if !ok {
break loop
}
pins = append(pins, p)
case <-ctx.Done():
return nil, ctx.Err()
case err := <-errCh:
if err != nil {
return nil, err
}
}
}()

if err := <-errCh; err != nil {
return nil, err
}
if err := <-ctxError; err != nil {
return nil, err
}

return pins, nil
Expand Down Expand Up @@ -286,7 +279,6 @@ func PinLsAll(ctx context.Context, typeStr string, pin pin.Pinner, dag ipld.DAGS
}
}
}
errCh <- nil
}()

return ch, errCh
Expand Down

0 comments on commit 219cf2d

Please sign in to comment.