mm1_core/context/
watching.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
use std::future::Future;

use mm1_address::address::Address;
use mm1_proto_system as system;
use mm1_proto_system::System;

use crate::context::call::Call;

pub trait Watching<Sys>:
    Call<Sys, system::Watch, Outcome = system::WatchRef> + Call<Sys, system::Unwatch, Outcome = ()>
where
    Sys: System,
{
    fn watch(&mut self, peer: Address) -> impl Future<Output = system::WatchRef> + Send
    where
        Sys: Default,
    {
        async move { self.call(Sys::default(), system::Watch { peer }).await }
    }

    fn unwatch(&mut self, wait_ref: system::WatchRef) -> impl Future<Output = ()> + Send
    where
        Sys: Default,
    {
        async move {
            self.call(
                Sys::default(),
                system::Unwatch {
                    watch_ref: wait_ref,
                },
            )
            .await
        }
    }
}

impl<Sys, T> Watching<Sys> for T
where
    T: Call<Sys, system::Watch, Outcome = system::WatchRef>
        + Call<Sys, system::Unwatch, Outcome = ()>,
    Sys: System,
{
}