Skip to content

Commit

Permalink
Update book regarding wait_indefinitely (google#201)
Browse files Browse the repository at this point in the history
  • Loading branch information
ia0 authored Aug 17, 2023
1 parent 798689c commit 23d4582
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 10 deletions.
8 changes: 4 additions & 4 deletions book/src/applet/prelude/button.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ to leak it. This is equivalent to calling `core::mem::forget()`.
{{#include button1.rs:leak}}
```

Finally, we just endlessly wait for callbacks. This step will eventually not be
needed. Waiting for callbacks indefinitely will be the implicit behavior when
`main` exits, in which case `main` can be seen as a callback setup procedure.
The `scheduling::wait_for_callback()` function puts the applet to sleep until a
Finally, we just endlessly wait for callbacks. This step is optional: waiting
for callbacks indefinitely is the implicit behavior when `main` exits. In some
way, `main` can be seen as a callback setup procedure. The
`scheduling::wait_for_callback()` function puts the applet to sleep until a
callback is scheduled and `scheduled::wait_indefinitely()` is just an infinite
loop around `wait_for_callback()`.

Expand Down
3 changes: 0 additions & 3 deletions book/src/applet/prelude/button2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,5 @@ fn main() {
button::Listener::new(button_index, handler).leak();
//} ANCHOR_END: listener
}

// We indefinitely wait for callbacks.
scheduling::wait_indefinitely();
}
//} ANCHOR_END: all
1 change: 1 addition & 0 deletions crates/prelude/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

### Patch

- Update documentation
- Fix clippy lints
- Update dependencies

Expand Down
2 changes: 2 additions & 0 deletions crates/prelude/src/scheduling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ pub fn wait_until(mut cond: impl FnMut() -> bool) {
}

/// Waits for callbacks indefinitely.
///
/// This is the default behavior when returning from `main()`.
pub fn wait_indefinitely() -> ! {
loop {
wait_for_callback();
Expand Down
3 changes: 0 additions & 3 deletions examples/rust/led/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,4 @@ fn main() {
// We indefinitely listen by creating and leaking a listener.
button::Listener::new(button_index, handler).leak();
}

// We indefinitely wait for callbacks.
scheduling::wait_indefinitely();
}

0 comments on commit 23d4582

Please sign in to comment.