Skip to content

Commit

Permalink
Revert "remove for statement"
Browse files Browse the repository at this point in the history
This reverts commit 1a4df04.
  • Loading branch information
mocyuto committed Jul 30, 2021
1 parent 1a4df04 commit 94347c7
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package keeper
import (
"context"
"errors"
"time"
)

var FailedGetChannel = errors.New("failed to get Channel")
Expand All @@ -29,13 +30,17 @@ func ExecWithContext(ctx context.Context, f func() (interface{}, error)) (interf
// wait channel result until context done
func waitResult(ctx context.Context, ch chan result) (interface{}, error) {
var i result
select {
case <-ctx.Done():
return i.value, ctx.Err()
case i, ok := <-ch:
if !ok {
return nil, FailedGetChannel
for {
select {
case <-ctx.Done():
return i.value, ctx.Err()
case i, ok := <-ch:
if !ok {
return nil, FailedGetChannel
}
return i.value, i.err
default:
}
return i.value, i.err
time.Sleep(1 * time.Millisecond)
}
}

0 comments on commit 94347c7

Please sign in to comment.