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
use async_std::task_local;
use std::cell::RefCell;
use crate::errors::{get_current_ctx, ErrorContext};
pub use crossbeam::channel::{bounded, unbounded, Receiver, RecvError, Select, SendError, Sender};
pub type ChannelWithContext<T> = (Sender<(T, ErrorContext)>, Receiver<(T, ErrorContext)>);
#[derive(Clone)]
pub struct SenderWithContext<T> {
sender: Sender<(T, ErrorContext)>,
}
impl<T: Clone> SenderWithContext<T> {
pub fn new(sender: Sender<(T, ErrorContext)>) -> Self {
Self { sender }
}
pub fn send(&self, event: T) -> Result<(), SendError<(T, ErrorContext)>> {
let err_ctx = get_current_ctx();
self.sender.send((event, err_ctx))
}
}
thread_local!(
pub static OPENCALLS: RefCell<ErrorContext> = RefCell::default()
);
task_local! {
pub static ASYNCOPENCALLS: RefCell<ErrorContext> = RefCell::default()
}