-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(runtime): Implement effect queue (#57)
- Loading branch information
Showing
16 changed files
with
153 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use std::{cell::RefCell, collections::VecDeque, fmt, sync::Arc}; | ||
|
||
use crate::Effect; | ||
|
||
#[derive(Clone)] | ||
pub struct EffectQueue<T: Clone + 'static> { | ||
queue: Arc<RefCell<VecDeque<Effect<T>>>>, | ||
} | ||
|
||
impl<T: Clone + 'static> EffectQueue<T> { | ||
pub fn new() -> EffectQueue<T> { | ||
EffectQueue { | ||
queue: Arc::new(RefCell::new(VecDeque::new())), | ||
} | ||
} | ||
|
||
pub fn count(effect_queue: &EffectQueue<T>) -> i32 { | ||
effect_queue.queue.borrow().len() as i32 | ||
} | ||
|
||
pub fn enqueue(effect_queue: &EffectQueue<T>, effect: Effect<T>) { | ||
if !Effect::is_none(&effect) { | ||
effect_queue.queue.borrow_mut().push_front(effect); | ||
} | ||
} | ||
|
||
pub fn dequeue(effect_queue: &EffectQueue<T>) -> Option<Effect<T>> { | ||
effect_queue.queue.borrow_mut().pop_back() | ||
} | ||
} | ||
|
||
// Implement Debug manually | ||
impl<T: Clone + 'static> fmt::Debug for EffectQueue<T> { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
// Build the debug representation | ||
f.debug_struct("EffectQueue").finish() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
namespace Functor | ||
open Fable.Core | ||
|
||
[<Erase; Emit("functor_runtime_common::EffectQueue<$0>")>] type EffectQueue<'msg> = | Noop | ||
|
||
|
||
module EffectQueue = | ||
|
||
[<Emit("functor_runtime_common::EffectQueue::new()")>] | ||
let empty (): EffectQueue<_> = nativeOnly | ||
|
||
[<Emit("functor_runtime_common::EffectQueue::count(&$0)")>] | ||
let count (effectQueue: EffectQueue<'a>): int = nativeOnly | ||
|
||
[<Emit("functor_runtime_common::EffectQueue::enqueue(&$1, $0)")>] | ||
let enqueue (eff: effect<'a>) (effectQueue: EffectQueue<'a>) : unit = nativeOnly | ||
|
||
[<Emit("functor_runtime_common::EffectQueue::dequeue(&$0)")>] | ||
let dequeue (effectQueue: EffectQueue<'a>): Option<effect<'a>> = nativeOnly |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters