@@ -30,6 +30,8 @@ This version has the following features relative to official V2.0:
30
30
* ` run_until_complete(coro()) ` now returns the value returned by ` coro() ` as
31
31
per CPython
32
32
[ micropython-lib PR270] ( https://github.com/micropython/micropython-lib/pull/270 ) .
33
+ * The ` StreamReader ` class now has a ` readinto(buf, n=0) ` method to enable
34
+ allocations to be reduced.
33
35
34
36
Note that priority device drivers are written by using the officially supported
35
37
technique for writing stream I/O drivers. Code using such drivers will run
@@ -64,6 +66,9 @@ formerly provided by `asyncio_priority.py` is now implemented.
64
66
3.1 [ Fast IO] ( ./FASTPOLL.md#31-fast-io )
65
67
3.2 [ Low Priority] ( ./FASTPOLL.md#32-low-priority )
66
68
3.3 [ Other Features] ( ./FASTPOLL.md#33-other-features )
69
+ 3.3.1 [ Version] ( ./FASTPOLL.md#331-version )
70
+ 3.3.2 [ got_event_loop] ( ./FASTPOLL.md#332-got_event_loop )
71
+ 3.3.3 [ StreamReader readinto method] ( ./FASTPOLL.md#333-streamreader-readinto-method )
67
72
3.4 [ Low priority yield] ( ./FASTPOLL.md#34-low-priority-yield )
68
73
3.4.1 [ Task Cancellation and Timeouts] ( ./FASTPOLL.md#341-task-cancellation-and-timeouts )
69
74
3.5 [ Low priority callbacks] ( ./FASTPOLL.md#35-low-priority-callbacks )
@@ -347,10 +352,14 @@ See [Low priority callbacks](./FASTPOLL.md#35-low-priority-callbacks)
347
352
348
353
## 3.3 Other Features
349
354
355
+ ### 3.3.1 Version
356
+
350
357
Variable:
351
- * ` version ` Returns a 2-tuple. Current contents ('fast_io', '0.24 '). Enables
358
+ * ` version ` Returns a 2-tuple. Current contents ('fast_io', '0.25 '). Enables
352
359
the presence and realease state of this version to be determined at runtime.
353
360
361
+ ### 3.3.2 got_event_loop
362
+
354
363
Function:
355
364
* ` got_event_loop() ` No arg. Returns a ` bool ` : ` True ` if the event loop has
356
365
been instantiated. Enables code using the event loop to raise an exception if
@@ -374,6 +383,31 @@ loop = asyncio.get_event_loop(runq_len=40, waitq_len=40)
374
383
This is mainly for retro-fitting to existing classes and functions. The
375
384
preferred approach is to pass the event loop to classes as a constructor arg.
376
385
386
+ ### 3.3.3 StreamReader readinto method
387
+
388
+ The purpose of this asynchronous method is to be a non-allocating complement to
389
+ the ` StreamReader.read ` method, enabling data to be read into a pre-existing
390
+ buffer. It assumes that the device driver providing the data has a ` readinto `
391
+ method.
392
+
393
+ ` StreamReader.readinto(buf, n=0) ` args:
394
+ ` buf ` the buffer to read into.
395
+ ` n=0 ` the maximum number of bytes to read - default the buffer size.
396
+ available it will be placed in the buffer. The return value is the number of
397
+ bytes read. The default maximum is the buffer size, otherwise the value of ` n ` .
398
+
399
+ The method will pause (allowing other coros to run) until data is available.
400
+
401
+ This method calls the synchronous ` readinto ` method of the data source. This
402
+ may take one arg (the buffer) or two (the buffer followed by the maximum number
403
+ of bytes to read). If ` StreamReader.readinto ` is launched with a single arg,
404
+ the ` readinto ` method will receive that one arg.
405
+
406
+ It is the reponsibility of the device ` readinto ` method to validate the args,
407
+ to populate the buffer and to return the number of bytes read. It should return
408
+ "immediately" with as much data as is available. It will only be called when
409
+ the ` ioctl ` method indicates that read data is ready.
410
+
377
411
###### [ Contents] ( ./FASTPOLL.md#contents )
378
412
379
413
## 3.4 Low priority yield
0 commit comments