Use a VecDequeue instead of a vec for bytes (#2246)
* Fix: add both the rAF queue and vecdequeue * Fix: Take before recycle
This commit is contained in:
1 parent
633e2a70a4
commit
0a3291084f
5 files changed
+26
-9
No files matched your search
@@ -1,17 +1,17 @@
|
||||
use std::{cell::RefCell, rc::Rc};
|
||||
use std::{cell::RefCell, collections::VecDeque, rc::Rc};
|
||||
|
||||
/// This handles communication between the requests that the webview makes and the interpreter. The interpreter constantly makes long running requests to the webview to get any edits that should be made to the DOM almost like server side events.
|
||||
/// It will hold onto the requests until the interpreter is ready to handle them and hold onto any pending edits until a new request is made.
|
||||
#[derive(Default, Clone)]
|
||||
pub(crate) struct EditQueue {
|
||||
queue: Rc<RefCell<Vec<Vec<u8>>>>,
|
||||
queue: Rc<RefCell<VecDeque<Vec<u8>>>>,
|
||||
responder: Rc<RefCell<Option<wry::RequestAsyncResponder>>>,
|
||||
}
|
||||
|
||||
impl EditQueue {
|
||||
pub fn handle_request(&self, responder: wry::RequestAsyncResponder) {
|
||||
let mut queue = self.queue.borrow_mut();
|
||||
if let Some(bytes) = queue.pop() {
|
||||
if let Some(bytes) = queue.pop_back() {
|
||||
responder.respond(wry::http::Response::new(bytes));
|
||||
} else {
|
||||
*self.responder.borrow_mut() = Some(responder);
|
||||
@@ -23,7 +23,7 @@ impl EditQueue {
|
||||
if let Some(responder) = responder.take() {
|
||||
responder.respond(wry::http::Response::new(edits));
|
||||
} else {
|
||||
self.queue.borrow_mut().push(edits);
|
||||
self.queue.borrow_mut().push_front(edits);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user