File tree Expand file tree Collapse file tree 1 file changed +26
-2
lines changed Expand file tree Collapse file tree 1 file changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -131,9 +131,33 @@ schedule code to be run straight away on the current thread. The implication
131
131
is that C < cue > on this scheduler will block until the code finishes
132
132
execution, limiting its utility to certain special cases such as testing.
133
133
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;
135
148
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
137
161
138
162
= head3 start
139
163
You can’t perform that action at this time.
0 commit comments