aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2022-08-29 00:54:14 +0200
committerDario Nieuwenhuis <[email protected]>2022-08-29 01:00:22 +0200
commit6392f067172541a0cb9b3757a9c7a40d3b7c5e25 (patch)
treea97b097fac0513dfeb42b2197b3e4b3aa7b00b9c
parent4c0f1b6354b1f1b2f87a6876bfa5d3803804cbb9 (diff)
futures: readme, docs improvements.
-rw-r--r--embassy-futures/Cargo.toml5
-rw-r--r--embassy-futures/README.md34
-rw-r--r--embassy-futures/src/block_on.rs2
-rw-r--r--embassy-futures/src/yield_now.rs17
4 files changed, 49 insertions, 9 deletions
diff --git a/embassy-futures/Cargo.toml b/embassy-futures/Cargo.toml
index e564f5a96..7123b7c61 100644
--- a/embassy-futures/Cargo.toml
+++ b/embassy-futures/Cargo.toml
@@ -6,9 +6,12 @@ edition = "2021"
6[package.metadata.embassy_docs] 6[package.metadata.embassy_docs]
7src_base = "https://github.com/embassy-rs/embassy/blob/embassy-futures-v$VERSION/embassy-futures/src/" 7src_base = "https://github.com/embassy-rs/embassy/blob/embassy-futures-v$VERSION/embassy-futures/src/"
8src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-futures/src/" 8src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-futures/src/"
9features = ["nightly"] 9features = ["defmt"]
10target = "thumbv7em-none-eabi" 10target = "thumbv7em-none-eabi"
11 11
12[package.metadata.docs.rs]
13features = ["defmt"]
14
12[dependencies] 15[dependencies]
13defmt = { version = "0.3", optional = true } 16defmt = { version = "0.3", optional = true }
14log = { version = "0.4.14", optional = true } 17log = { version = "0.4.14", optional = true }
diff --git a/embassy-futures/README.md b/embassy-futures/README.md
index 3810bcafd..7add22c7b 100644
--- a/embassy-futures/README.md
+++ b/embassy-futures/README.md
@@ -1,10 +1,28 @@
1# embassy-futures 1# embassy-futures
2 2
3Utilities for working with futures: 3An [Embassy](https://embassy.dev) project.
4 4
5- [`select`](select::select) - waiting for one out of two futures to complete. 5Utilities for working with futures, compatible with `no_std` and not using `alloc`. Optimized for code size,
6- [`select3`](select::select3) - waiting for one out of three futures to complete. 6ideal for embedded systems.
7- [`select4`](select::select4) - waiting for one out of four futures to complete. 7
8- [`select_array`](select::select_array) - waiting for one future in an array of futures to complete. 8- Future combinators, like [`join`](join) and [`select`](select)
9- [`select_slice`](select::select_slice) - waiting for one future in a slice of futures to complete. 9- Utilities to use `async` without a fully fledged executor: [`block_on`](block_on::block_on) and [`yield_now`](yield_now::yield_now).
10- [`yield_now`](yield_now::yield_now) - yielding the current task. 10
11## Interoperability
12
13Futures from this crate can run on any executor.
14
15## Minimum supported Rust version (MSRV)
16
17Embassy is guaranteed to compile on the latest stable Rust version at the time of release. It might compile with older versions but that may change in any new patch release.
18
19## License
20
21This work is licensed under either of
22
23- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or
24 <http://www.apache.org/licenses/LICENSE-2.0>)
25- MIT license ([LICENSE-MIT](LICENSE-MIT) or <http://opensource.org/licenses/MIT>)
26
27at your option.
28
diff --git a/embassy-futures/src/block_on.rs b/embassy-futures/src/block_on.rs
index 749fa67f3..da90351ec 100644
--- a/embassy-futures/src/block_on.rs
+++ b/embassy-futures/src/block_on.rs
@@ -11,6 +11,8 @@ static VTABLE: RawWakerVTable = RawWakerVTable::new(|_| RawWaker::new(ptr::null(
11/// the current thread at 100% cpu usage until the future is done. The 11/// the current thread at 100% cpu usage until the future is done. The
12/// future's `Waker` mechanism is not used. 12/// future's `Waker` mechanism is not used.
13/// 13///
14/// You can use this to run multiple futures concurrently with [`join`][crate::join].
15///
14/// It's suitable for systems with no or limited concurrency and without 16/// It's suitable for systems with no or limited concurrency and without
15/// strict requirements around power consumption. For more complex use 17/// strict requirements around power consumption. For more complex use
16/// cases, prefer using a "real" executor like `embassy-executor`, which 18/// cases, prefer using a "real" executor like `embassy-executor`, which
diff --git a/embassy-futures/src/yield_now.rs b/embassy-futures/src/yield_now.rs
index 1ebecb916..13b103778 100644
--- a/embassy-futures/src/yield_now.rs
+++ b/embassy-futures/src/yield_now.rs
@@ -3,6 +3,23 @@ use core::pin::Pin;
3use core::task::{Context, Poll}; 3use core::task::{Context, Poll};
4 4
5/// Yield from the current task once, allowing other tasks to run. 5/// Yield from the current task once, allowing other tasks to run.
6///
7/// This can be used to easily and quickly implement simple async primitives
8/// without using wakers. The following snippet will wait for a condition to
9/// hold, while still allowing other tasks to run concurrently (not monopolizing
10/// the executor thread).
11///
12/// ```rust,no_run
13/// while !some_condition() {
14/// yield_now().await;
15/// }
16/// ```
17///
18/// The downside is this will spin in a busy loop, using 100% of the CPU, while
19/// using wakers correctly would allow the CPU to sleep while waiting.
20///
21/// The internal implementation is: on first poll the future wakes itself and
22/// returns `Poll::Pending`. On second poll, it returns `Poll::Ready`.
6pub fn yield_now() -> impl Future<Output = ()> { 23pub fn yield_now() -> impl Future<Output = ()> {
7 YieldNowFuture { yielded: false } 24 YieldNowFuture { yielded: false }
8} 25}