MCPcopy Create free account
hub / github.com/RustOtomeLab/RustEng / new

Method new

src/executors/text_executor.rs:14–55  ·  view source on GitHub ↗
(weak: Weak<MainWindow>)

Source from the content-addressed store, hash-verified

12
13impl TextExecutor {
14 pub(crate) fn new(weak: Weak<MainWindow>) -> (Self, Sender<Arc<RwLock<DisplayText>>>) {
15 let (full_text_tx, mut full_text_rx) = channel::<Arc<RwLock<DisplayText>>>(10);
16 let (text_tx, text_rx) = std::sync::mpsc::channel::<String>();
17 let timer = slint::Timer::default();
18
19 let executor = Self {
20 timer,
21 weak,
22 text_rx: Some(text_rx),
23 };
24
25 tokio::spawn(async move {
26 while let Some(text) = full_text_rx.recv().await {
27 let speed = text.read().unwrap().speed;
28 if speed == Duration::from_millis(0) {
29 let mut text = text.write().unwrap();
30 let tx = text_tx.clone();
31 if let Err(e) = tx.send(text.full_text.clone()) {
32 eprintln!("text channel closed: {e}");
33 return;
34 }
35 text.is_running = false;
36 continue;
37 }
38 while text.read().unwrap().is_running {
39 let tx = text_tx.clone();
40 {
41 let mut text = text.write().unwrap();
42 if let Some(text) = text.next_character() {
43 if let Err(e) = tx.send(text) {
44 eprintln!("text channel closed: {e}");
45 return;
46 }
47 }
48 }
49 sleep(speed).await;
50 }
51 }
52 });
53
54 (executor, full_text_tx)
55 }
56
57 pub(crate) fn start_timer(&mut self) {
58 let weak = self.weak.clone();

Callers

nothing calls this directly

Calls 1

next_characterMethod · 0.80

Tested by

no test coverage detected