@@ -6,6 +6,10 @@ code size and high performance on bare metal targets. This repository provides
6
6
documentation, tutorial material and code to aid in its effective use. It also
7
7
contains an optional ` fast_io ` variant of ` uasyncio ` .
8
8
9
+ Damien has completely rewritten ` uasyncio ` . Its release is likely to be
10
+ imminent, see
11
+ [ PR5332] ( https://github.com/micropython/micropython/pull/5332 ) and [ section 3.1] ( ./README.md##31-the-new_version ) .
12
+
9
13
## The fast_io variant
10
14
11
15
This comprises two parts.
@@ -70,6 +74,78 @@ installation instructions where `uasyncio` is not pre-installed.
70
74
71
75
# 3. uasyncio development state
72
76
77
+ ## 3.1 The new version
78
+
79
+ This complete rewrite of ` uasyncio ` supports CPython 3.8 syntax. A design aim
80
+ is that it should be be a compatible subset of ` asyncio ` . Many applications
81
+ using the coding style advocated in the tutorial will work unchanged. The
82
+ following features will involve minor changes to application code:
83
+
84
+ * Task cancellation: ` cancel ` is now a method of a ` Task ` instance.
85
+ * Event loop methods: ` call_at ` , ` call_later ` , ` call_later_ms ` and
86
+ ` call_soon ` are no longer supported. In CPython docs these are
87
+ [ lightly deprecated] ( https://docs.python.org/3/library/asyncio-eventloop.html#preface )
88
+ in application code; there are simple workrounds.
89
+ * ` yield ` in coroutines should be replaced by ` await asyncio.sleep_ms(0) ` :
90
+ this is in accord with CPython where ` yield ` will produce a syntax error.
91
+ * Awaitable classes: currently under discussion. The ` __iter__ ` method works
92
+ but ` yield ` should be replaced by ` await asyncio.sleep_ms(0) ` . As yet I have
93
+ found no way to write an awaitable classes compatible with the new ` uasyncio `
94
+ and which does not throw syntax errors under CPython 3.8/` asyncio ` .
95
+
96
+ ### 3.1.1 Implications for this repository
97
+
98
+ It is planned to retain V2 under a different name. The new version fixes bugs
99
+ which have been outstanding for a long time. In my view V2 is best viewed as
100
+ deprecated. I will retain V2-specific code and docs in a separate directory,
101
+ with the rest of this repo being adapted for the new version.
102
+
103
+ #### 3.1.1.1 Tutorial
104
+
105
+ This requires only minor changes.
106
+
107
+ #### 3.1.1.2 Fast I/O
108
+
109
+ The ` fast_io ` fork is incompatible and will be relegated to the V2 directory.
110
+
111
+ The new version's design greatly simplifies the implementation of fast I/O:
112
+ I therefore hope the new ` uasyncio ` will include it. The other principal aims
113
+ were to provide workrounds for bugs now fixed. If ` uasyncio ` includes fast I/O
114
+ there is no reason to fork the new version; other ` fast_io ` features will be
115
+ lost unless Damien sees fit to implement them. The low priority task option is
116
+ little used and arguably is ill-conceived: I will not be advocating for its
117
+ inclusion.
118
+
119
+ #### 3.1.1.3 Synchronisation Primitives
120
+
121
+ The CPython ` asyncio ` library supports these synchronisation primitives:
122
+ * ` Lock ` - already incorporated in new ` uasyncio ` .
123
+ * ` Event ` - already incorporated.
124
+ * ` gather ` - already incorporated.
125
+ * ` Semaphore ` and ` BoundedSemaphore ` . My classes work under new version.
126
+ * ` Condition ` . Works under new version.
127
+ * ` Queue ` . This was implemented by Paul Sokolvsky in ` uasyncio.queues ` .
128
+
129
+ Incorporating these will produce more efficient implementations; my solutions
130
+ were designed to work with stock ` uasyncio ` V2.
131
+
132
+ The ` Event ` class in ` asyn.py ` provides a nonstandard option to supply a data
133
+ value to the ` .set ` method and to retrieve this with ` .value ` . It is also an
134
+ awaitable class. I will support these by subclassing the native ` Event ` .
135
+
136
+ The following work under new and old versions:
137
+ * ` Barrier ` (now adapted).
138
+ * ` Delay_ms ` (this and the following in aswitch.py)
139
+ * ` Switch `
140
+ * ` Pushbutton `
141
+
142
+ The following were workrounds for bugs and omissions in V2 which are now fixed.
143
+ They will be removed.
144
+ * The cancellation decorators and classes (cancellation works as per CPython).
145
+ * The nonstandard support for ` gather ` (now properly supported).
146
+
147
+ ## 3.2 The current version V2.0
148
+
73
149
These notes are intended for users familiar with ` asyncio ` under CPython.
74
150
75
151
The MicroPython language is based on CPython 3.4. The ` uasyncio ` library
@@ -99,13 +175,13 @@ It supports millisecond level timing with the following:
99
175
100
176
Classes ` Task ` and ` Future ` are not supported.
101
177
102
- ## 3.1 Asynchronous I/O
178
+ ## 3.2. 1 Asynchronous I/O
103
179
104
180
Asynchronous I/O (` StreamReader ` and ` StreamWriter ` classes) support devices
105
181
with streaming drivers, such as UARTs and sockets. It is now possible to write
106
182
streaming device drivers in Python.
107
183
108
- ## 3.2 Time values
184
+ ## 3.2.2 Time values
109
185
110
186
For timing asyncio uses floating point values of seconds. The ` uasyncio.sleep `
111
187
method accepts floats (including sub-second values) or integers. Note that in
0 commit comments