Skip to content

Commit 03f2f85

Browse files
committed
Better and less racey example of Supply.share
1 parent e1e225b commit 03f2f85

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

doc/Type/Supply.pod

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -221,16 +221,16 @@ Creates an on-demand supply from the values passed to this method.
221221
222222
method share(Supply:D:) returns Supply:D
223223
224-
my $s = Supply.from-list(^100000).share;
225-
my @first;
226-
$s.tap: { @first.push($_) };
227-
my @second;
228-
$s.tap: { @second.push($_) };
229-
say @first + @second;
230-
231224
Creates a live supply from an on-demand supply, thus making it possible to
232225
share the values of the on-demand supply on multiple taps, instead of each
233-
tap seeing all values from the on-demand supply.
226+
tap seeing its own copy of all values from the on-demand supply.
227+
228+
# this says in turn: "first 1" "first 2" "second 2" "first 3" "second 3"
229+
my $s = Supply.interval(1).share;
230+
$s.tap: { "first $_".say };
231+
sleep 1.1;
232+
$s.tap: { "second $_".say };
233+
sleep 2
234234
235235
=head2 method flat
236236

0 commit comments

Comments
 (0)