func New()

in internal/filter/types/watchlist/watchlist.go [51:82]


func New(ctx context.Context, in chan watch.Event, out chan data.Entry, options ...Option) (*Filter, error) {
	ctx = context.WithoutCancel(ctx)

	cc := &Filter{
		in:     in,
		out:    out,
		logger: slog.Default(),
	}

	for _, o := range options {
		if err := o(cc); err != nil {
			return nil, err
		}
	}
	if cc.m == nil {
		cc.m = map[types.UID]items.Item{}
	}

	g := wait.Group{}

	g.Go(ctx, func(ctx context.Context) error {
		cc.run(ctx)
		return nil
	})

	go func() {
		g.Wait(ctx)
		close(cc.out)
	}()

	return cc, nil
}