@@ -5,6 +5,50 @@ task monitoring and cancellation.
5
5
6
6
###### [ Main README] ( ./README.md )
7
7
8
+ # Contents
9
+
10
+ 1 . [ The asyn.py library] ( ./PRIMITIVES.md#1-the-asyn.py-library )
11
+
12
+ 1.1 [ Synchronisation Primitives] ( ./PRIMITIVES.md#11-synchronisation-primitives )
13
+
14
+ 1.2 [ Task control and monitoring] ( ./PRIMITIVES.md#12-task-control-and-monitoring )
15
+
16
+ 2 . [ Modules] ( ./PRIMITIVES.md#2-modules )
17
+
18
+ 3 [ Synchronisation Primitives] ( ./PRIMITIVES.md#3-synchronisation-primitives )
19
+
20
+ 3.1 [ Function launch] ( ./PRIMITIVES.md#31-function-launch )
21
+
22
+ 3.2 [ Class Lock] ( ./PRIMITIVES.md#32-class-lock )
23
+
24
+ 3.2.1 [ Definition] ( ./PRIMITIVES.md#321-definition )
25
+
26
+ 3.3 [ Class Event] ( ./PRIMITIVES.md#33-class-event )
27
+
28
+ 3.3.1 [ Definition] ( ./PRIMITIVES.md#331-definition )
29
+
30
+ 3.4 [ Class Barrier] ( ./PRIMITIVES.md#34-class-barrier )
31
+
32
+ 3.5 [ Class Semaphore] ( ./PRIMITIVES.md#35-class-semaphore )
33
+
34
+ 3.5.1 [ Class BoundedSemaphore] ( ./PRIMITIVES.md#351-class-boundedsemaphore )
35
+
36
+ 4 . [ Task Cancellation] ( ./PRIMITIVES.md#4-task-cancellation )
37
+
38
+ 4.1 [ Coro sleep] ( ./PRIMITIVES.md#41-coro-sleep )
39
+
40
+ 4.2 [ Class Cancellable] ( ./PRIMITIVES.md#42-class-cancellable )
41
+
42
+ 4.2.1 [ Groups] ( ./PRIMITIVES.md#421-groups )
43
+
44
+ 4.2.2 [ Custom cleanup] ( ./PRIMITIVES.md#422-custom-cleanup )
45
+
46
+ 4.3 [ Class NamedTask] ( ./PRIMITIVES.md#43-class-namedtask )
47
+
48
+ 4.3.1 [ Latency and Barrier objects] ( ./PRIMITIVES.md#431-latency-and-barrier-objects )
49
+
50
+ 4.3.2 [ Custom cleanup] ( ./PRIMITIVES.md#432-custom-cleanup )
51
+
8
52
## 1.1 Synchronisation Primitives
9
53
10
54
There is often a need to provide synchronisation between coros. A common
@@ -25,17 +69,15 @@ arrival (with other coros getting scheduled for the duration). The `Queue`
25
69
guarantees that items are removed in the order in which they were received. As
26
70
this is a part of the uasyncio library its use is described in the [ tutorial] ( ./TUTORIAL.md ) .
27
71
72
+ ###### [ Contents] ( ./PRIMITIVES.md#contents )
73
+
28
74
## 1.2 Task control and monitoring
29
75
30
76
` uasyncio ` does not implement the ` Task ` and ` Future ` classes of ` asyncio ` .
31
77
Instead it uses a 'micro' lightweight means of task cancellation. The ` asyn.py `
32
78
module provides an API to simplify its use and to check on the running status
33
79
of coroutines which are subject to cancellation.
34
80
35
- ** NOTE** The task cancellation API has changed. Hopefully it is now stable.
36
-
37
- ###### [ Main README] ( ./README.md )
38
-
39
81
# 2. Modules
40
82
41
83
The following modules are provided:
@@ -46,6 +88,8 @@ The following modules are provided:
46
88
47
89
Import the test or demo module for a list of available tests.
48
90
91
+ ###### [ Contents] ( ./PRIMITIVES.md#contents )
92
+
49
93
# 3. Synchronisation Primitives
50
94
51
95
The primitives are intended for use only with ` uasyncio ` . They are ` micro ` in
@@ -107,6 +151,8 @@ Methods:
107
151
* ` acquire ` No args. Coro which pauses until the lock has been acquired. Use
108
152
by executing ` await lock.acquire() ` .
109
153
154
+ ###### [ Contents] ( ./PRIMITIVES.md#contents )
155
+
110
156
## 3.3 Class Event
111
157
112
158
This provides a way for one or more coros to pause until another one flags them
@@ -167,6 +213,8 @@ Synchronous Methods:
167
213
The optional data value may be used to compensate for the latency in awaiting
168
214
the event by passing ` loop.time() ` .
169
215
216
+ ###### [ Contents] ( ./PRIMITIVES.md#contents )
217
+
170
218
## 3.4 Class Barrier
171
219
172
220
This enables multiple coros to rendezvous at a particular point. For example
@@ -222,6 +270,8 @@ async def foo(n):
222
270
Note that ` await barrier(nowait = True) ` should not be issued in a looping
223
271
construct.
224
272
273
+ ###### [ Contents] ( ./PRIMITIVES.md#contents )
274
+
225
275
## 3.5 Class Semaphore
226
276
227
277
A semaphore limits the number of coros which can access a resource. It can be
@@ -258,8 +308,13 @@ This works identically to the `Semaphore` class except that if the `release`
258
308
method causes the access counter to exceed its initial value, a ` ValueError `
259
309
is raised.
260
310
311
+ ###### [ Contents] ( ./PRIMITIVES.md#contents )
312
+
261
313
# 4. Task Cancellation
262
314
315
+ Note to users of releases prior to 31st Dec 2017: this API has changed. It
316
+ should now be stable.
317
+
263
318
In ` uasyncio ` task cancellation is achieved by throwing an exception to the
264
319
coro to be cancelled. Cancellation occurs when it is next scheduled. If a coro
265
320
issues ` await uasyncio.sleep(secs) ` or ` uasyncio.sleep_ms(ms) ` scheduling will
@@ -407,6 +462,8 @@ async def bar(task_id):
407
462
Cancellable.end(task_no)
408
463
```
409
464
465
+ ###### [ Contents] ( ./PRIMITIVES.md#contents )
466
+
410
467
## 4.3 Class NamedTask
411
468
412
469
A ` NamedTask ` instance is associated with a user-defined name such that the
@@ -509,6 +566,8 @@ async def foo(_):
509
566
return False
510
567
```
511
568
569
+ ###### [ Contents] ( ./PRIMITIVES.md#contents )
570
+
512
571
#### ExitGate (obsolete)
513
572
514
573
This was a nasty hack to fake task cancellation at a time when uasyncio did not
0 commit comments