You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Timer type
* Minor cleanup; clarify Timer type use cases
* Clarify Timer precision
* More small updates to the README
* More small updates to the README
* More small updates to the README
This crate is an **experimental** fork of the splendid [`async-io`](https://github.com/smol-rs/async-io) crate targetting MCUs and ESP-IDF in particular.
10
+
This crate is an experimental fork of the splendid [`async-io`](https://github.com/smol-rs/async-io) crate targetting MCUs and ESP-IDF in particular.
11
11
12
12
## How to use?
13
13
14
-
`async-io-mini` is a drop-in, API-compatible replacement for the `Async`type from `async-io` (but does NOT have an equivalent of `Timer` - see why [below](#limitations)).
14
+
`async-io-mini` is a drop-in, API-compatible replacement for the `Async`and `Timer` types from `async-io`.
15
15
16
16
So either:
17
17
* Just replace all `use async_io` occurances in your crate with `use async_io_mini`
@@ -37,40 +37,53 @@ Further, `async-io` has a non-trivial set of dependencies (again - for MCUs; for
37
37
-`log` (might become optional);
38
38
-`enumset` (not crucial, might remove).
39
39
40
-
## Limitations
40
+
## Enhancements
41
+
42
+
The `Timer` type of `async_io_mini` is based on the `embassy-time` crate, and as such should offer a higher resolution on embedded operating systems like the ESP-IDF than what can be normally achieved by implementing timers using the `timeout` parameter of the `select` syscall (as `async-io` does).
41
43
42
-
### No timers
44
+
The reason for this is that on the ESP-IDF, the `timeout` parameter of `select` provides a resolution of 10ms (one FreeRTOS sys-tick), while
45
+
`embassy-time` is implemented using the [ESP-IDF Timer service](https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/system/esp_timer.html), which provides resolutions up to 1 microsecond.
43
46
44
-
`async-io-mini` does NOT have an equivalent of `async_io::Timer`. On ESP-IDF at least, timers based on OS systicks are often not very useful, as the OS systick is low-res (10ms).
47
+
With that said, for greenfield code that does not need to be compatible with `async-io`, use the native `embassy_time::Timer` and `embassy_time::Ticker` rather than `async_io_mini::Timer`, because the latter has a larger memory footprint (40 bytes on 32bit archs) compared to the `embassy-time` types (8 and 16 bytes each).
45
48
46
-
Workaround: use the `Timer` struct from the [`embassy-time`](https://crates.io/crates/embassy-time) crate, which provides a very similar API and is highly optimized for embedded environments. On the ESP-IDF, the `embassy-time-driver` implementation is backed by the ESP-IDF Timer service, which runs off from a high priority thread by default and thus has good res.
49
+
## Limitations
47
50
48
51
### No equivalent of `async_io::block_on`
49
52
50
53
Implementing socket polling as a shared task between the hidden `async-io-mini` thread and the thread calling `async_io_mini::block_on` is not trivial and probably not worth it on MCUs. Just use `futures_lite::block_on` or the `block_on` equivalent for your OS (i.e. `esp_idf_svc::hal::task::block_on` for the ESP-IDF).
51
54
52
55
## Implementation
53
56
57
+
### Async
58
+
54
59
The first time `Async` is used, a thread named `async-io-mini` will be spawned.
55
60
The purpose of this thread is to wait for I/O events reported by the operating system, and then
56
61
wake appropriate futures blocked on I/O when they can be resumed.
57
62
58
63
To wait for the next I/O event, the "async-io-mini" thread uses the [select](https://en.wikipedia.org/wiki/Select_(Unix)) syscall, and **is thus only useful for MCUs (might just be the ESP-IDF) where the number of file or socket handles is very small anyway**.
59
64
65
+
### Timer
66
+
67
+
As per above, the `Timer` type is a wrapper around the functionality provided by the `embassy-time` crate.
68
+
60
69
## Examples
61
70
62
-
Connect to `example.com:80`.
71
+
Connect to `example.com:80`, or time out after 10 seconds.
0 commit comments