Skip to content

Commit

Permalink
feat: migrate to immediate processing
Browse files Browse the repository at this point in the history
  • Loading branch information
shikanime committed Jan 23, 2025
1 parent 45881a4 commit 312beca
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
3 changes: 3 additions & 0 deletions cmd/format/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ func Run(v *viper.Viper, statz *stats.Stats, cmd *cobra.Command, paths []string)
if errors.Is(err, io.EOF) {
// we have finished traversing
break
} else if errors.Is(err, context.DeadlineExceeded) && cfg.Watch {
// we timed out reading files, try again
continue
} else if err != nil {
// something went wrong
return fmt.Errorf("failed to read files: %w", err)
Expand Down
2 changes: 2 additions & 0 deletions format/composite.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ func (c *CompositeFormatter) Apply(ctx context.Context, files []*walk.File) erro
}
}

c.scheduler.apply(ctx)

return nil
}

Expand Down
4 changes: 3 additions & 1 deletion format/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,14 +203,16 @@ func (s *scheduler) schedule(ctx context.Context, key batchKey, batch []*walk.Fi
})
}

func (s *scheduler) close(ctx context.Context) error {
func (s *scheduler) apply(ctx context.Context) {
// schedule any partial batches that remain
for key, batch := range s.batches {
if len(batch) > 0 {
s.schedule(ctx, key, batch)
}
}
}

func (s *scheduler) close(ctx context.Context) error {
// wait for processing to complete
if err := s.eg.Wait(); err != nil {
return fmt.Errorf("failed to wait for formatters: %w", err)
Expand Down

0 comments on commit 312beca

Please sign in to comment.