ntex_async_std/
signals.rs1use std::{cell::RefCell, future::Future, pin::Pin, rc::Rc, task::Context, task::Poll};
2
3thread_local! {
4 static SRUN: RefCell<bool> = const { RefCell::new(false) };
5 static SHANDLERS: Rc<RefCell<Vec<oneshot::Sender<Signal>>>> = Default::default();
6}
7
8#[derive(PartialEq, Eq, Clone, Copy, Debug)]
10pub enum Signal {
11 Hup,
13 Int,
15 Term,
17 Quit,
19}
20
21pub fn signal() -> Option<oneshot::Receiver<Signal>> {
26 if !SRUN.with(|v| *v.borrow()) {
27 async_std::task::spawn_local(Signals::new());
28 }
29 SHANDLERS.with(|handlers| {
30 let (tx, rx) = oneshot::channel();
31 handlers.borrow_mut().push(tx);
32 Some(rx)
33 })
34}
35
36struct Signals {}
37
38impl Signals {
39 pub(super) fn new() -> Signals {
40 Self {}
41 }
42}
43
44impl Future for Signals {
45 type Output = ();
46
47 fn poll(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Self::Output> {
48 Poll::Ready(())
49 }
50}