mm1_core/context/
watching.rs

1use std::future::Future;
2
3use mm1_address::address::Address;
4use mm1_proto_system as system;
5use mm1_proto_system::System;
6
7use crate::context::call::Call;
8
9pub trait Watching<Sys>:
10    Call<Sys, system::Watch, Outcome = system::WatchRef> + Call<Sys, system::Unwatch, Outcome = ()>
11where
12    Sys: System,
13{
14    fn watch(&mut self, peer: Address) -> impl Future<Output = system::WatchRef> + Send
15    where
16        Sys: Default,
17    {
18        async move { self.call(Sys::default(), system::Watch { peer }).await }
19    }
20
21    fn unwatch(&mut self, wait_ref: system::WatchRef) -> impl Future<Output = ()> + Send
22    where
23        Sys: Default,
24    {
25        async move {
26            self.call(
27                Sys::default(),
28                system::Unwatch {
29                    watch_ref: wait_ref,
30                },
31            )
32            .await
33        }
34    }
35}
36
37impl<Sys, T> Watching<Sys> for T
38where
39    T: Call<Sys, system::Watch, Outcome = system::WatchRef>
40        + Call<Sys, system::Unwatch, Outcome = ()>,
41    Sys: System,
42{
43}