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

Method stream

canvas/src/canvas.rs:136–159  ·  view source on GitHub ↗

Creates a stream for reading the instructions from this canvas

(&self)

Source from the content-addressed store, hash-verified

134 /// Creates a stream for reading the instructions from this canvas
135 ///
136 pub fn stream(&self) -> impl Stream<Item=Draw>+Send {
137 // Create a new canvas stream
138 let new_core = Arc::new(Desync::new(DrawStreamCore::new()));
139 let new_stream = DrawStream::with_core(&new_core);
140
141 // Register it and send the current set of pending commands to it
142 let add_stream = Arc::clone(&new_core);
143 self.core.desync(move |core| {
144 // Send the data we've received since the last clear
145 add_stream.sync(|stream| {
146 stream.write(iter::once(Draw::ResetFrame));
147 stream.write(core.main_core.get_pending_drawing())
148 });
149
150 // Store the stream in the core so future notifications get sent there
151 core.streams.push(Arc::downgrade(&add_stream));
152
153 // Wake the stream if it's not awake
154 add_stream.sync(|stream| stream.take_waker().map(|waker| waker.wake()));
155 });
156
157 // Return the new stream
158 new_stream
159 }
160
161 ///
162 /// Retrieves the list of drawing actions in this canvas

Calls 4

get_pending_drawingMethod · 0.80
mapMethod · 0.80
take_wakerMethod · 0.80
writeMethod · 0.45