Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions packages/yew/src/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ fn with(f: impl FnOnce(&mut Scheduler)) {
#[inline]
pub(crate) fn push(runnable: Box<dyn Runnable>) {
with(|s| s.main.push_back(runnable));
// Execute pending immediately. Necessary for runnables added outside the component lifecycle,
// which would otherwise be delayed.
start();
}

/// Push a component creation Runnable to be executed
Expand Down Expand Up @@ -113,3 +116,27 @@ impl Scheduler {
.or_else(|| self.main.pop_front())
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn push_executes_runnables_immediately() {
use std::cell::Cell;

thread_local! {
static FLAG: Cell<bool> = Default::default();
}

struct Test;
impl Runnable for Test {
fn run(self: Box<Self>) {
FLAG.with(|v| v.set(true));
}
}

push(Box::new(Test));
FLAG.with(|v| assert!(v.get()));
}
}