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
Copy file name to clipboardExpand all lines: README.md
+12-5Lines changed: 12 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,7 @@ This crate is an **experimental** fork of the splendid [`async-io`](https://gith
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,26 +37,33 @@ 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
41
42
-
### No timers
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.
43
43
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).
44
+
The reason for this is that on the ESP-IDF, the `timeout` parameter of `select` provides a minimum resolution of 10ms (one FreeRTOS sys-tick), while
45
+
`embassy-time` is implemented using ESP-IDF Timer service, which provides resolutions up to 1 microsecond.
45
46
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.
47
+
## Limitations
47
48
48
49
### No equivalent of `async_io::block_on`
49
50
50
51
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
52
52
53
## Implementation
53
54
55
+
### Async
56
+
54
57
The first time `Async` is used, a thread named `async-io-mini` will be spawned.
55
58
The purpose of this thread is to wait for I/O events reported by the operating system, and then
56
59
wake appropriate futures blocked on I/O when they can be resumed.
57
60
58
61
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
62
63
+
### Timer
64
+
65
+
As per above, the `Timer` type is a wrapper around the functionality provided by the `embassy-time` crate.
0 commit comments