Skip to content

Commit 76c3921

Browse files
committed
start on Promises
1 parent 3c3ce18 commit 76c3921

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

lib/Language/concurrency.pod

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,33 @@ schedule code to be run straight away on the current thread. The implication
131131
is that C<cue> on this scheduler will block until the code finishes
132132
execution, limiting its utility to certain special cases such as testing.
133133
134-
=begin comment
134+
=head2 Promises
135+
136+
A L<Promise> can be thought of as encapsulating the result of the execution
137+
of some code that may not have completed or even started at the time the
138+
promise is obtained. They provide much of the functionality that user code
139+
will need to operate in a concurrent or asynchronous manner.
140+
141+
At simplest promises can be thought of as a mechanism for asynchronously
142+
chaining the results of various callable code:
143+
144+
my $promise1 = Promise.new();
145+
my $promise2 = $promise1.then(-> $v { say $v.result; "Second Result"});
146+
$promise1.keep("First Result");
147+
say $promise2.result;
135148
136-
=head2 promises
149+
Here the C<then> schedules code to be executed when the first L<Promise>
150+
is kept or broken, itself returning a new L<Promise> which will be kept
151+
with the result of the code when it is executed (or broken if the code
152+
fails.) C<keep> changes the status of the promise to C<Kept> setting
153+
the result to the positional argument. C<result> blocks the current
154+
thread of execution until the promise is kept or broken, if it was kept
155+
then it will return the result (that is the value passed to C<keep>, )
156+
or it will throw an exception based on the value passed to C<break>.
157+
158+
159+
160+
=begin comment
137161
138162
=head3 start
139163

0 commit comments

Comments
 (0)