Skip to content

Commit

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

var FailedGetChannel = errors.New("failed to get Channel")
Expand All @@ -30,17 +29,13 @@ 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
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:
select {
case <-ctx.Done():
return i.value, ctx.Err()
case i, ok := <-ch:
if !ok {
return nil, FailedGetChannel
}
time.Sleep(1 * time.Millisecond)
return i.value, i.err
}
}

0 comments on commit 1a4df04

Please sign in to comment.