MCPcopy Create free account
hub / github.com/Logicalshift/flo_draw / write

Method write

canvas/src/canvas.rs:32–67  ·  view source on GitHub ↗

Writes to the canvas core

(&mut self, actions: Vec<Draw>)

Source from the content-addressed store, hash-verified

30 /// Writes to the canvas core
31 ///
32 pub fn write(&mut self, actions: Vec<Draw>) -> Vec<Waker> {
33 // Write to the main core
34 self.main_core.write(actions.iter().cloned());
35
36 // Write to each of the streams
37 let mut remove_idx = vec![];
38 let mut wakers = vec![];
39
40 for (idx, stream) in self.streams.iter().enumerate() {
41 if let Some(stream) = stream.upgrade() {
42 wakers.push(stream.sync(|stream| {
43 stream.write(iter::once(Draw::StartFrame));
44 stream.write(actions.iter().cloned());
45 stream.write(iter::once(Draw::ShowFrame));
46 stream.take_waker()
47 }));
48 } else {
49 remove_idx.push(idx);
50 }
51 }
52
53 // Tidy any streams that are no longer listening
54 if remove_idx.len() > 0 {
55 let remove_idx = remove_idx.into_iter().collect::<HashSet<_>>();
56 let old_streams = mem::take(&mut self.streams);
57
58 self.streams = old_streams.into_iter()
59 .enumerate()
60 .filter(|(idx, _item)| !remove_idx.contains(idx))
61 .map(|(_idx, item)| item)
62 .collect();
63 }
64
65 // Return the wakers
66 wakers.into_iter().flatten().collect()
67 }
68}
69
70///

Callers 7

newMethod · 0.45
streamMethod · 0.45
dropMethod · 0.45
can_draw_to_canvasFunction · 0.45
can_follow_canvas_streamFunction · 0.45
can_follow_many_streamsFunction · 0.45

Calls 2

take_wakerMethod · 0.80
mapMethod · 0.80

Tested by 4

can_draw_to_canvasFunction · 0.36
can_follow_canvas_streamFunction · 0.36
can_follow_many_streamsFunction · 0.36