State management
This commit is contained in:
+8
-6
@@ -4,6 +4,14 @@ fn main() -> std::io::Result<()> {
|
||||
let screen = Screen::new();
|
||||
let count = use_state(0);
|
||||
|
||||
std::thread::spawn({
|
||||
let count = count.clone();
|
||||
move || loop {
|
||||
std::thread::sleep(std::time::Duration::from_millis(1000));
|
||||
**count.get() += 500;
|
||||
}
|
||||
});
|
||||
|
||||
screen
|
||||
.draw(
|
||||
Dependency::new({
|
||||
@@ -14,11 +22,5 @@ fn main() -> std::io::Result<()> {
|
||||
)
|
||||
.component(Transform::center());
|
||||
|
||||
std::thread::spawn(move || loop {
|
||||
std::thread::sleep(std::time::Duration::from_millis(900));
|
||||
let c = (*count).clone();
|
||||
count.set(c + 1);
|
||||
});
|
||||
|
||||
screen.run()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user