@@ -896,32 +896,34 @@ tested in slow time by the task.
896
896
897
897
## 3.7 Barrier
898
898
899
- This is an unofficial primitive and has no analog in CPython asyncio. It is
900
- based on a Microsoft primitive. While similar in purpose to ` gather ` there
899
+ This is an unofficial primitive and has no counterpart in CPython asyncio. It
900
+ is based on a Microsoft primitive. While similar in purpose to ` gather ` there
901
901
are differences described below.
902
902
903
- It two uses. Firstly it can allow a task to pause until one or more other tasks
904
- have terminated. For example an application might want to shut down various
905
- peripherals before starting a sleep period. The task wanting to sleep initiates
906
- several shut down tasks and waits until they have triggered the barrier to
907
- indicate completion.
908
-
909
- Secondly it enables multiple coros to rendezvous at a particular point. For
910
- example producer and consumer coros can synchronise at a point where the
911
- producer has data available and the consumer is ready to use it. At that point
912
- in time the ` Barrier ` can optionally run a callback before releasing the
903
+ Its principal purpose is to cause multiple coros to rendezvous at a particular
904
+ point. For example producer and consumer coros can synchronise at a point where
905
+ the producer has data available and the consumer is ready to use it. At that
906
+ point in time the ` Barrier ` can optionally run a callback before releasing the
913
907
barrier to allow all waiting coros to continue.
914
908
909
+ Secondly it can allow a task to pause until one or more other tasks have
910
+ terminated or passed a particular point. For example an application might want
911
+ to shut down various peripherals before starting a sleep period. The task
912
+ wanting to sleep initiates several shut down tasks and waits until they have
913
+ triggered the barrier to indicate completion. This use case may be better
914
+ served by ` gather ` .
915
+
915
916
The key difference between ` Barrier ` and ` gather ` is symmetry: ` gather ` is
916
917
asymmetrical. One task owns the ` gather ` and awaits completion of a set of
917
918
tasks. By contrast ` Barrier ` can be used symmetrically with member tasks
918
919
pausing until all have reached the barrier. This makes it suited for use in
919
- the looping constructs common in firmware applications.
920
+ the ` while True: ` constructs common in firmware applications. Use of ` gather `
921
+ would imply instantiating a set of tasks on every pass of the loop.
920
922
921
- ` gather ` provides ready access to return values. The ` Barrier ` class cannot
922
- because passing the barrier does not imply return.
923
+ ` gather ` provides access to return values; irrelevant to ` Barrier ` because
924
+ passing a barrier does not imply return.
923
925
924
- Currently ` gather ` is more efficient; I plan to fix this .
926
+ Currently ` gather ` is more efficient.
925
927
926
928
Constructor.
927
929
Mandatory arg:
0 commit comments