Skip to content

Commit 4757c99

Browse files
authored
Make Supply.wait and related docs more precise
Make it very clear that these methods all perform a `.tap` and start a flow of values. For those who understand the `Supply` model well already, it will be clear that this is the only way it could work, but there is a tendency to assume that the C<wait>, in particular, somehow could relate to an earlier tapping. Also correct the `wait` return value documentation, and describe the error semantics of other methods.
1 parent 6ac1882 commit 4757c99

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

doc/Type/Supply.pod6

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,10 @@ the GUI thread.
158158
159159
method wait(Supply:D:)
160160
161-
Waits until the supply is done (in which case it returns C<True>) or C<quit>
162-
(in which case it will throw the exception that was passed to C<quit>).
161+
Taps the C<Supply> it is called on, and blocks execution until the either the supply
162+
is C<done> (in which case it evaluates to the final value that was emitted on the
163+
C<Supply>, or C<Nil> if not value was emitted) or C<quit> (in which case it will throw
164+
the exception that was passed to C<quit>).
163165
164166
my $s = Supplier.new;
165167
start {
@@ -176,16 +178,19 @@ Waits until the supply is done (in which case it returns C<True>) or C<quit>
176178
177179
method list(Supply:D: --> List:D)
178180
179-
Waits until the supply is done, then returns a list of all values emitted
180-
since the C<list> call.
181+
Taps the C<Supply> it is called on, and returns a lazy list that will be reified
182+
as the C<Supply> emits values. The list will be terminated once the C<Supply> is
183+
C<done>. If the C<Supply> C<quit>s, then an exception will be thrown once that
184+
point in the lazy list is reached.
181185
182186
=head2 method grab
183187
184188
method grab(Supply:D: &when-done --> Supply:D)
185189
186-
Waits until the given C<Supply> is done. It will then call the C<&when-done>
187-
closure passing all of the values seen, Then creates a C<Supply> to which all
188-
values returned from the C<&when-done> closure are emitted.
190+
Taps the C<Supply> it is called on. When it is C<done>, calls C<&when-done> and
191+
then emits the list of values that it returns on the result C<Supply>. If the
192+
original C<Supply> C<quit>s, then the exception is immediately conveyed on the
193+
return C<Supply>.
189194
190195
my $s = Supply.from-list(4, 10, 3, 2);
191196
my $t = $s.grab(&sum);
@@ -195,8 +200,10 @@ values returned from the C<&when-done> closure are emitted.
195200
196201
method reverse(Supply:D: --> Supply:D)
197202
198-
Waits until the given C<Supply> is done, then creates a C<Supply> to which all
199-
values seen are emitted in reverse order.
203+
Taps the C<Supply> it is called on. Once that C<Supply> emits C<done>, all of the
204+
values it emitted will be emitted on the returned C<Supply> in reverse order. If
205+
the original C<Supply> C<quit>s, then the exception is immediately conveyed on the
206+
return C<Supply>.
200207
201208
my $s = Supply.from-list(1, 2, 3);
202209
my $t = $s.reverse;
@@ -206,9 +213,11 @@ values seen are emitted in reverse order.
206213
207214
method sort(Supply:D: &custom-routine-to-use? --> Supply:D)
208215
209-
Waits until the given C<Supply> is done, then creates a C<Supply> to which all
210-
values seen are emitted in sorted order. Optionally accepts a comparator
211-
L<Block|/type/Block>.
216+
Taps the C<Supply> it is called on. Once that C<Supply> emits C<done>, all of the
217+
values that it emitted will be sorted, and the results emitted on the returned
218+
C<Supply> in the sorted order. Optionally accepts a comparator L<Block|/type/Block>.
219+
If the original C<Supply> C<quit>s, then the exception is immediately conveyed on the
220+
return C<Supply>.
212221
213222
my $s = Supply.from-list(4, 10, 3, 2);
214223
my $t = $s.sort();

0 commit comments

Comments
 (0)