From 99e6e2547f28bb20bb98edc0f71e1f2f546511b0 Mon Sep 17 00:00:00 2001 From: anchalshivank Date: Tue, 9 Sep 2025 01:27:15 +0530 Subject: [PATCH] feat(webrtc): add three tuple watcher implementation --- src/lib.rs | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 736d9bf..7465fe2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -418,6 +418,53 @@ impl Watcher for (S, T) { } } +impl Watcher for (S, T, U) { + type Value = (S::Value, T::Value, U::Value); + + fn get(&mut self) -> Self::Value { + (self.0.get(), self.1.get(), self.2.get()) + } + + fn is_connected(&self) -> bool { + self.0.is_connected() && self.1.is_connected() && self.2.is_connected() + } + + fn poll_updated( + &mut self, + cx: &mut task::Context<'_>, + ) -> Poll> { + let poll_0 = self.0.poll_updated(cx)?; + let poll_1 = self.1.poll_updated(cx)?; + let poll_2 = self.2.poll_updated(cx)?; + + match (poll_0, poll_1, poll_2) { + // If all are ready + (Poll::Ready(s), Poll::Ready(t), Poll::Ready(u)) => Poll::Ready(Ok((s, t, u))), + // If any one is ready, get current values for the others + (Poll::Ready(s), Poll::Ready(t), Poll::Pending) => { + Poll::Ready(Ok((s, t, self.2.get()))) + } + (Poll::Ready(s), Poll::Pending, Poll::Ready(u)) => { + Poll::Ready(Ok((s, self.1.get(), u))) + } + (Poll::Pending, Poll::Ready(t), Poll::Ready(u)) => { + Poll::Ready(Ok((self.0.get(), t, u))) + } + (Poll::Ready(s), Poll::Pending, Poll::Pending) => { + Poll::Ready(Ok((s, self.1.get(), self.2.get()))) + } + (Poll::Pending, Poll::Ready(t), Poll::Pending) => { + Poll::Ready(Ok((self.0.get(), t, self.2.get()))) + } + (Poll::Pending, Poll::Pending, Poll::Ready(u)) => { + Poll::Ready(Ok((self.0.get(), self.1.get(), u))) + } + // If none are ready + (Poll::Pending, Poll::Pending, Poll::Pending) => Poll::Pending, + } + } +} + /// Combinator to join two watchers #[derive(Debug, Clone)] pub struct Join> {