This repository has been archived on 2024-05-03. You can view files and clone it, but cannot push or open issues or pull requests.
treefmt/internal/format/context.go

22 lines
675 B
Go
Raw Normal View History

2023-12-23 12:50:47 +00:00
package format
import (
"context"
)
const (
completedChKey = "completedCh"
)
2023-12-24 11:59:05 +00:00
// SetCompletedChannel is used to set a channel for indication processing completion in the provided context.
2023-12-23 12:50:47 +00:00
func SetCompletedChannel(ctx context.Context, completedCh chan string) context.Context {
return context.WithValue(ctx, completedChKey, completedCh)
}
// MarkPathComplete is used to indicate that all processing has finished for the provided path.
2023-12-24 11:59:05 +00:00
// This is done by adding the path to the completion channel which should have already been set using
// SetCompletedChannel.
func MarkPathComplete(ctx context.Context, path string) {
2023-12-23 12:50:47 +00:00
ctx.Value(completedChKey).(chan string) <- path
}