Start removing the Send impl for App

Co-authored-by: Antonio <antonio@zed.dev>
Co-authored-by: Nathan <nathan@zed.dev>
This commit is contained in:
Max Brunsfeld
2023-11-01 13:53:45 -06:00
committed by Nathan Sobo
co-authored by Antonio Nathan
parent ea7fdef417
commit 57ffa8201e
38 changed files with 506 additions and 932 deletions
@@ -215,58 +215,3 @@ impl PlatformDispatcher for TestDispatcher {
Some(self)
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::Executor;
use std::sync::Arc;
#[test]
fn test_dispatch() {
let dispatcher = TestDispatcher::new(StdRng::seed_from_u64(0));
let executor = Executor::new(Arc::new(dispatcher));
let result = executor.block(async { executor.run_on_main(|| 1).await });
assert_eq!(result, 1);
let result = executor.block({
let executor = executor.clone();
async move {
executor
.spawn_on_main({
let executor = executor.clone();
assert!(executor.is_main_thread());
|| async move {
assert!(executor.is_main_thread());
let result = executor
.spawn({
let executor = executor.clone();
async move {
assert!(!executor.is_main_thread());
let result = executor
.spawn_on_main({
let executor = executor.clone();
|| async move {
assert!(executor.is_main_thread());
2
}
})
.await;
assert!(!executor.is_main_thread());
result
}
})
.await;
assert!(executor.is_main_thread());
result
}
})
.await
}
});
assert_eq!(result, 2);
}
}
+14 -6
View File
@@ -1,21 +1,29 @@
use crate::{DisplayId, Executor, Platform, PlatformTextSystem};
use crate::{BackgroundExecutor, DisplayId, ForegroundExecutor, Platform, PlatformTextSystem};
use anyhow::{anyhow, Result};
use std::sync::Arc;
pub struct TestPlatform {
executor: Executor,
background_executor: BackgroundExecutor,
foreground_executor: ForegroundExecutor,
}
impl TestPlatform {
pub fn new(executor: Executor) -> Self {
TestPlatform { executor }
pub fn new(executor: BackgroundExecutor, foreground_executor: ForegroundExecutor) -> Self {
TestPlatform {
background_executor: executor,
foreground_executor,
}
}
}
// todo!("implement out what our tests needed in GPUI 1")
impl Platform for TestPlatform {
fn executor(&self) -> Executor {
self.executor.clone()
fn background_executor(&self) -> BackgroundExecutor {
self.background_executor.clone()
}
fn foreground_executor(&self) -> ForegroundExecutor {
self.foreground_executor.clone()
}
fn text_system(&self) -> Arc<dyn PlatformTextSystem> {