1use anyhow::Result;
2use async_trait::async_trait;
3use crb_agent::{Address, Agent};
4use crb_runtime::{InterruptionLevel, Interruptor};
5use tokio::{select, signal};
6
7#[async_trait]
8pub trait Main {
9 async fn join_or_signal(self) -> Result<()>;
10}
11
12#[async_trait]
13impl<A> Main for Address<A>
14where
15 A: Agent,
16 A::Context: Default,
17{
18 async fn join_or_signal(mut self) -> Result<()> {
19 let mut level = InterruptionLevel::EVENT;
20 loop {
21 select! {
22 _ = signal::ctrl_c() => {
23 self.interrupt_with_level(level);
24 level = level.next();
25 }
26 _ = self.join() => {
27 break;
28 }
29 }
30 }
31 Ok(())
32 }
33}