Restructure Peer to handle connections' messages in order

This commit is contained in:
Max Brunsfeld
2021-07-09 16:27:34 -07:00
parent b7fae693f9
commit eeebc761b6
14 changed files with 479 additions and 274 deletions
+16
View File
@@ -104,8 +104,11 @@ pub enum MenuItem<'a> {
#[derive(Clone)]
pub struct App(Rc<RefCell<MutableAppContext>>);
#[derive(Clone)]
pub struct AsyncAppContext(Rc<RefCell<MutableAppContext>>);
pub struct BackgroundAppContext(*const RefCell<MutableAppContext>);
#[derive(Clone)]
pub struct TestAppContext {
cx: Rc<RefCell<MutableAppContext>>,
@@ -409,6 +412,15 @@ impl TestAppContext {
}
impl AsyncAppContext {
pub fn spawn<F, Fut, T>(&self, f: F) -> Task<T>
where
F: FnOnce(AsyncAppContext) -> Fut,
Fut: 'static + Future<Output = T>,
T: 'static,
{
self.0.borrow().foreground.spawn(f(self.clone()))
}
pub fn read<T, F: FnOnce(&AppContext) -> T>(&mut self, callback: F) -> T {
callback(self.0.borrow().as_ref())
}
@@ -433,6 +445,10 @@ impl AsyncAppContext {
self.0.borrow().platform()
}
pub fn foreground(&self) -> Rc<executor::Foreground> {
self.0.borrow().foreground.clone()
}
pub fn background(&self) -> Arc<executor::Background> {
self.0.borrow().cx.background.clone()
}