Skip to content

Commit

Permalink
fix: main watch loop cancel context
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaschain committed Dec 4, 2023
1 parent 6e7a084 commit 4c1267b
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions infrastructure/file_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,13 @@ func FileWatcher(paths []string, callback core.ChangeCallback, ctx context.Conte
}
defer watcher.Close()

loopCtx, cancel := context.WithCancelCause(ctx)

go func() {
commandError := loop(watcher, callback)

if commandError != nil {
ctx.Done()
cancel(*commandError)
}
}()

Expand All @@ -54,7 +56,7 @@ func FileWatcher(paths []string, callback core.ChangeCallback, ctx context.Conte
}
}

<-ctx.Done()
<-loopCtx.Done()

err = ctx.Err()
return &err
Expand Down

0 comments on commit 4c1267b

Please sign in to comment.