summaryrefslogtreecommitdiffstats
path: root/src/queue.rs
diff options
context:
space:
mode:
authorStephan Dilly <dilly.stephan@gmail.com>2021-06-07 22:57:27 +0200
committerStephan Dilly <dilly.stephan@gmail.com>2021-06-07 22:57:27 +0200
commit7058ab14d3ad1b8f3fffe2bc2a52729127eb1bef (patch)
tree79668a3ce7b6f7f526687c11b0d0ce7c40835623 /src/queue.rs
parentab5b29e0eeec955f31b3fb5334d3c4cf211c16ad (diff)
abstract queue into custom type
Diffstat (limited to 'src/queue.rs')
-rw-r--r--src/queue.rs27
1 files changed, 25 insertions, 2 deletions
diff --git a/src/queue.rs b/src/queue.rs
index be2fc06b..b50b9d53 100644
--- a/src/queue.rs
+++ b/src/queue.rs
@@ -85,5 +85,28 @@ pub enum InternalEvent {
OpenFileTree(CommitId),
}
-///
-pub type Queue = Rc<RefCell<VecDeque<InternalEvent>>>;
+/// single threaded simple queue for components to communicate with each other
+#[derive(Clone)]
+pub struct Queue {
+ data: Rc<RefCell<VecDeque<InternalEvent>>>,
+}
+
+impl Queue {
+ pub fn new() -> Self {
+ Self {
+ data: Rc::new(RefCell::new(VecDeque::new())),
+ }
+ }
+
+ pub fn push(&self, ev: InternalEvent) {
+ self.data.borrow_mut().push_back(ev);
+ }
+
+ pub fn pop(&self) -> Option<InternalEvent> {
+ self.data.borrow_mut().pop_front()
+ }
+
+ pub fn clear(&self) {
+ self.data.borrow_mut().clear();
+ }
+}