Skip to content

Commit 53c368d

Browse files
committed
V3 Barrier primitive: access callback return value, improve docs.
1 parent 9e11d1f commit 53c368d

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

v3/docs/TUTORIAL.md

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -896,32 +896,34 @@ tested in slow time by the task.
896896

897897
## 3.7 Barrier
898898

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
901901
are differences described below.
902902

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
913907
barrier to allow all waiting coros to continue.
914908

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+
915916
The key difference between `Barrier` and `gather` is symmetry: `gather` is
916917
asymmetrical. One task owns the `gather` and awaits completion of a set of
917918
tasks. By contrast `Barrier` can be used symmetrically with member tasks
918919
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.
920922

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.
923925

924-
Currently `gather` is more efficient; I plan to fix this.
926+
Currently `gather` is more efficient.
925927

926928
Constructor.
927929
Mandatory arg:

0 commit comments

Comments
 (0)