Skip to content

Commit

Permalink
Check context errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ajnavarro committed Sep 16, 2022
1 parent b95a96a commit 8826fba
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions compsequential.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ func getValueOrErrorSequential[T any](
f func(context.Context, routing.Routing) (T, bool, error),
) (value T, err error) {
for _, router := range routers {
if ctxErr := ctx.Err(); ctxErr != nil {
return value, ctxErr
}

ctx, cancel := context.WithTimeout(ctx, router.Timeout)
defer cancel()
value, empty, err := f(ctx, router.Router)
Expand All @@ -166,6 +170,9 @@ func executeSequential(
f func(context.Context, routing.Routing,
) error) error {
for _, router := range routers {
if ctxErr := ctx.Err(); ctxErr != nil {
return ctxErr
}
ctx, cancel := context.WithTimeout(ctx, router.Timeout)
if err := f(ctx, router.Router); err != nil &&
!errors.Is(err, routing.ErrNotFound) &&
Expand All @@ -189,6 +196,11 @@ func getChannelOrErrorSequential[T any](

go func() {
for _, router := range routers {
if ctxErr := ctx.Err(); ctxErr != nil {
close(chanOut)
return
}

ctx, cancel := context.WithTimeout(ctx, router.Timeout)
rch, err := f(ctx, router.Router)
if err != nil &&
Expand Down

0 comments on commit 8826fba

Please sign in to comment.