Skip to content

Commit 0319bd4

Browse files
committed
Tutorial mentions gather and condition.
1 parent 97653a3 commit 0319bd4

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

PRIMITIVES.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
# 1. The asyn.py library
22

3-
This provides five simple synchronisation primitives, together with an API for
3+
This provides some simple synchronisation primitives, together with an API for
44
task monitoring and cancellation. Task cancellation requires usayncio V 1.7.1
55
or higher. At the time of writing (7th Jan 2018) it requires a daily build of
66
MicroPython firmware or one built from source.
77

8+
The library is too large to run on the ESP8266 except as frozen bytecode. An
9+
obvious workround is to produce a version with unused primitives removed.
10+
811
###### [Main README](./README.md)
912

1013
# Contents
@@ -395,7 +398,9 @@ See `asyntest.py` function `gather_test()`.
395398
The `Gatherable` class has no user methods. The constructor takes a coro by
396399
name followed by any positional or keyword arguments for the coro. If an arg
397400
`timeout` is provided it should have an integer or float value: this is taken
398-
to be the timeout for the coro in seconds.
401+
to be the timeout for the coro in seconds. Note that timeout is subject to the
402+
latency discussed in [Coroutines with timeouts](./TUTORIAL.md#44-coroutines-with-timeouts).
403+
A way to reduce this is to use `asyn.sleep()` in such coros.
399404

400405
The `Gather` class has no user methods. The constructor takes one mandatory
401406
arg: a list of `Gatherable` instances.

TUTORIAL.md

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ $ python3 -m micropip.py install -p ~/syn micropython-uasyncio
9595

9696
3.6 [Task cancellation](./TUTORIAL.md#36-task-cancellation)
9797

98+
3.7 [Other synchronisation primitives](./TUTORIAL.md#37-other-synchronisation-primitives)
99+
98100
4. [Designing classes for asyncio](./TUTORIAL.md#4-designing-classes-for-asyncio)
99101

100102
4.1 [Awaitable classes](./TUTORIAL.md#41-awaitable-classes)
@@ -393,7 +395,7 @@ may be found [here](./PRIMITIVES.md).
393395

394396
## 3.1 Lock
395397

396-
This describes the use of the official `Lock` primitive. [Full details.](./PRIMITIVES.md#32-class-lock)
398+
This describes the use of the official `Lock` primitive.
397399

398400
This guarantees unique access to a shared resource. In the following code
399401
sample a `Lock` instance `lock` has been created and is passed to all coros
@@ -433,9 +435,10 @@ and the timeout is triggered while it is waiting on a lock, the timeout will be
433435
ineffective. It will not receive the `TimeoutError` until it has acquired the
434436
lock. The same observation applies to task cancellation.
435437

436-
The module `asyn.py` offers a `Lock` class which works in these situations. It
437-
is significantly less efficient than the official class but supports additional
438-
interfaces as per the CPython version including context manager usage.
438+
The module `asyn.py` offers a `Lock` class which works in these situations
439+
[Full details.](./PRIMITIVES.md#32-class-lock). It is significantly less
440+
efficient than the official class but supports additional interfaces as per the
441+
CPython version including context manager usage.
439442

440443
###### [Contents](./TUTORIAL.md#contents)
441444

@@ -658,6 +661,22 @@ async def foo():
658661

659662
###### [Contents](./TUTORIAL.md#contents)
660663

664+
## 3.7 Other synchronisation primitives
665+
666+
The `asyn.py` library provides 'micro' implementations of CPython capabilities,
667+
namely the [Condition class](./PRIMITIVES.md#36-class-condition) and the
668+
[gather](./PRIMITIVES.md#37-class-gather) method.
669+
670+
The `Condition` class enables a coro to notify other coros which are waiting on
671+
a locked resource. Once notified they will access the resource and release the
672+
lock in turn. The notifying coro can limit the number of coros to be notified.
673+
674+
The CPython `gather` method enables a list of coros to be launched. When the
675+
last has completed a list of results is returned. This 'micro' implementation
676+
uses different syntax. Timeouts may be applied to any of the coros.
677+
678+
###### [Contents](./TUTORIAL.md#contents)
679+
661680
# 4 Designing classes for asyncio
662681

663682
In the context of device drivers the aim is to ensure nonblocking operation.

0 commit comments

Comments
 (0)