Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
resource: Refactor the API for simplified usage
As Resource[T] was used more it became apparent that making it an stream.Observable and having Event[T] be an interface makes it inconvenient to use: - Almost always we're subscribing to it for the whole duration of the application and do not need to handle completion errors. Consuming the events via a channel is also often the preferred way as it always "for-select" over multiple resources. - Event[T] contains almost the same payload for all event types, we might as well keep it simple and just use a single struct. This changes Observe() into `Events(ctx, opts) <-chan Event[T]` and moves rate limiting and error handling to be per-subscriber options. Event[T] becomes a single struct with a kind tag to specific event type. In order to handle large datasets at startup the events are now emitted immediately rather than waiting for informer to synchronize the store first. The BenchmarkResource in resource_test.go was also ported to current master and the difference between the unbuffered channel approach to callback was about 2x (2600ns/op for channels, 1350ns/op for callbacks), which is negligble enough. Benchmark was also ran with buffered event channel with no difference to unbuffered. Unbuffered is preferable as allows better chances for coalescing away the intermediate updates for objects with the same key. Signed-off-by: Jussi Maki <jussi@isovalent.com>
- Loading branch information