Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: cancel parallel routers #71

Merged
merged 2 commits into from
Feb 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions compparallel.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@ func (r *composableParallel) FindProvidersAsync(ctx context.Context, cid cid.Cid
return r.FindProvidersAsync(ctx, cid, count), nil
},
func() bool {
return atomic.AddInt64(&totalCount, 1) > int64(count) && count != 0
if count == 0 {
return false
}
return atomic.AddInt64(&totalCount, 1) >= int64(count)
},
)

Expand Down Expand Up @@ -369,23 +372,24 @@ func getChannelOrErrorParallel[T any](
return
}

if shouldStop() {
log.Debug("getChannelOrErrorParallel: stopping channel iteration for router ", r.Router,
select {
case <-ctx.Done():
log.Debug("getChannelOrErrorParallel: stopping execution on router on context done inside select for router ", r.Router,
" with timeout ", r.Timeout,
" and ignore errors ", r.IgnoreError,
" closed channel: ", ok,
)
return
case outCh <- val:
}

select {
case <-ctx.Done():
log.Debug("getChannelOrErrorParallel: stopping execution on router on context done inside select for router ", r.Router,
if shouldStop() {
log.Debug("getChannelOrErrorParallel: stopping channel iteration for router ", r.Router,
" with timeout ", r.Timeout,
" and ignore errors ", r.IgnoreError,
" closed channel: ", ok,
)
cancelAll()
return
case outCh <- val:
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"version": "v0.6.0"
"version": "v0.6.1"
}