-
-
Notifications
You must be signed in to change notification settings - Fork 284
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
Add a WatchStreamExt trait for stream chaining #899
Conversation
Codecov Report
@@ Coverage Diff @@
## master #899 +/- ##
==========================================
+ Coverage 70.35% 70.61% +0.25%
==========================================
Files 62 64 +2
Lines 4291 4339 +48
==========================================
+ Hits 3019 3064 +45
- Misses 1272 1275 +3
|
Signed-off-by: clux <sszynrae@gmail.com>
Signed-off-by: clux <sszynrae@gmail.com>
Signed-off-by: clux <sszynrae@gmail.com>
// present a dumb table for it for now. maybe drop the whole watch. kubectl does not do it anymore. | ||
let mut stream = try_flatten_applied(w).boxed(); | ||
// present a dumb table for it for now. kubectl does not do this anymore. | ||
let mut stream = watcher(api, lp).watch_applies().boxed(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be pin_mut!
rather than boxed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, i am using it elsewhere. i just don't want to mix pin into the easy go-to example.
All in all, minor implementation nits but much happier with the new API! We should probably either delete the old flatteners, or turn them into (deprecated) aliases for the new trait methods. |
Signed-off-by: clux <sszynrae@gmail.com>
Signed-off-by: clux <sszynrae@gmail.com>
Signed-off-by: clux <sszynrae@gmail.com>
Signed-off-by: clux <sszynrae@gmail.com>
Signed-off-by: clux <sszynrae@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Happy to kill off try_flatten_*
and merge this now then.
I'm going to mark those as deprecated (with notice of removal in 0.75.0) and then update all the examples first. |
Deprecation is good enough to me. |
Signed-off-by: clux <sszynrae@gmail.com>
Signed-off-by: clux <sszynrae@gmail.com>
Signed-off-by: clux <sszynrae@gmail.com>
/// | ||
/// All Added/Modified events are passed through, and critical errors bubble up. | ||
/// This is functionally equivalent to calling [`try_flatten_applied`] on a [`watcher`]. | ||
fn watch_applies<K>(self) -> EventFlatten<Self, K> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it's just me, but WatchStreamExt::watch_applies
and WatchStreamExt::watch_touches
sounds kind of awkward.
applied_objects
and touched_objects
?
watcher(api, lp).applied_objects()
watcher(api, lp).touched_objects()
reflector(store, watcher(api, lp)).applied_objects()
trigger_with(watcher(api, lp).touched_objects(), |obj| {})
Or even just applied
and touched
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, I personally like those better myself, even the short variants makes sense to me.
if not the short ones, then at the very least the _objects
suffix is better than a watch prefix - which is almost implied by the trait.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Raised a PR in #906 for this.
as suggested by #899 (review) Signed-off-by: clux <sszynrae@gmail.com>
* Rename unreleased watcher ext methods slightly as suggested by #899 (review) Signed-off-by: clux <sszynrae@gmail.com> * fix forgotten references to old method in docs Signed-off-by: clux <sszynrae@gmail.com> * accidental private Signed-off-by: clux <sszynrae@gmail.com> * ugh fmt reorder Signed-off-by: clux <sszynrae@gmail.com>
From discussion with @teozkr after #698 in december.
This tries to solve the problem in a more generic way using
Stream
helpers.A single example using it is included for now. Want to have some reviews before tidying this up properly...well, i had free time now, have tidied.It was not trivial (but followed similar bits from tokio-stream following the StreamExt setup). it might not be the best way to do this, but every other path i tried failed.
EDIT: Note the methods in here were further renamed in #906 before the 0.72.0 release.
failed path
tried a smarter setup without having to reimplement `into_iter_applied` inlined into an `impl Stream` but i just couldn't get the types to line up. the `impl Stream` we get is opaque and cannot be put inside the struct `AppliesGen` ```rust #[pin_project] /// Stream returned by the [`Applies`](super::WatchStreamExt::watch_applies) method. #[must_use = "streams do nothing unless polled"] pub struct AppliesGen { #[pin] stream: St, phantom: PhantomData, } impl AppliesGen where K: Sized + Send + 'static, St: Stream, watcher::Error>> + 'static, { pub(super) fn new(st: St) -> Self { let stream = utils::try_flatten_applied(st); // opaque type :( AppliesGen { stream, phantom: PhantomData } } } impl Stream for AppliesGen where { type Item = Result;
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<OptionSelf::Item> {
self.as_mut()
.project()
.stream
.poll_next(cx)
}
}