Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⚠ Apply predicates on handler instead of passing them to the source #1

Conversation

inteon
Copy link

@inteon inteon commented Apr 22, 2024

This is a proposed change to kubernetes-sigs#2783.
In kubernetes-sigs#2783, the API of the Source is changed and the handler and predicates are passed to the source when constructed instead of through the Start function.
This PR proposes to further improve that API and make the sources unaware of predicates, instead predicates are used to filter what events are passed to the handler by wrapping the handler and returning a new handler (see WithPredicates function).

alvaroaleman and others added 2 commits April 20, 2024 22:07
This change add generic versions of event, handler and predicates along
the existing ones, prefixed with `Typed`. The existing ones are left in
place under the same signature.

The `source` constructors are changed to be generic.
…handler with a predicates filter and pass the new handler to the source

Signed-off-by: Tim Ramlot <42113979+inteon@users.noreply.github.com>
// Channel is used to provide a source of events originating outside the cluster
// (e.g. GitHub Webhook callback). Channel requires the user to wire the external
// source (e.g. http handler) to write GenericEvents to the underlying channel.
func Channel[T any](source <-chan event.TypedGenericEvent[T], handler handler.TypedEventHandler[T], predicates ...predicate.TypedPredicate[T]) Source {
func Channel[T any](source <-chan event.TypedGenericEvent[T], handler handler.TypedEventHandler[T], options ...ChannelOption) Source {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the predicates are now passed to WithPredicates instead of this function, we can add an options variadic argument and use that to configure eg. the buffer size.

@inteon
Copy link
Author

inteon commented May 6, 2024

Implemented in kubernetes-sigs#2783.

@inteon inteon closed this May 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants