From 312beca1e4de36c5fc5e6fdcc4520862f75663df Mon Sep 17 00:00:00 2001 From: William Phetsinorath Date: Thu, 23 Jan 2025 11:32:11 +0000 Subject: [PATCH] feat: migrate to immediate processing --- cmd/format/format.go | 3 +++ format/composite.go | 2 ++ format/scheduler.go | 4 +++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/cmd/format/format.go b/cmd/format/format.go index 041a28de..42232116 100644 --- a/cmd/format/format.go +++ b/cmd/format/format.go @@ -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) diff --git a/format/composite.go b/format/composite.go index d5ac4558..d16b0f54 100644 --- a/format/composite.go +++ b/format/composite.go @@ -107,6 +107,8 @@ func (c *CompositeFormatter) Apply(ctx context.Context, files []*walk.File) erro } } + c.scheduler.apply(ctx) + return nil } diff --git a/format/scheduler.go b/format/scheduler.go index beac3292..c8117e3b 100644 --- a/format/scheduler.go +++ b/format/scheduler.go @@ -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)