You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+78-7Lines changed: 78 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -114,7 +114,9 @@ $suspension->suspend();
114
114
print '++ Script end' . PHP_EOL;
115
115
```
116
116
117
-
Callbacks registered on the Revolt event-loop are automatically run as coroutines and it's safe to suspend them. Apart from the event-loop API, `Amp\async()` can be used to start an independent call stack.
117
+
Callbacks registered on the Revolt event-loop are automatically run as coroutines. It is safe to suspend within those
118
+
callbacks. Apart from the event-loop API, `Amp\async()` can be used to start a coroutine (that is, a new fiber or an
A `Future` is an object representing the eventual result of an asynchronous operation. Such placeholders are also
141
-
called "promises" in other frameworks or languages such as JavaScript. We chose to not use the "promises" name as a
143
+
called a "promise" in other frameworks or languages such as JavaScript. We chose to not use the "promise" name since a
142
144
`Future` does not have a `then` method, which is typical of most promise implementations. Futures are primarily designed
143
145
to be awaited in coroutines, though `Future` also has methods which act upon the result, returning another future.
144
146
@@ -166,8 +168,8 @@ The callback approach has several drawbacks.
166
168
167
169
- Passing callbacks and doing further actions in them that depend on the result of the first action gets messy really
168
170
quickly.
169
-
- An explicit callback is required as input parameter to the function, and the return value is simply unused. There's no
170
-
way to use this API without involving a callback.
171
+
- An explicit callback is required as input parameter to the function, and the return value is simply unused. There's
172
+
no way to use this API without involving a callback.
171
173
172
174
That's where futures come into play.
173
175
They're placeholders for the result that are returned like any other return value.
@@ -304,9 +306,9 @@ Once result is ready, you complete the `Future` held by the caller using `comple
304
306
```php
305
307
final class DeferredFuture
306
308
{
307
-
public function getFuture(): Future;
308
-
public function complete(mixed $value = null);
309
-
public function error(Throwable $throwable);
309
+
public function getFuture(): Future
310
+
public function complete(mixed $value = null): void
311
+
public function error(Throwable $throwable): void
310
312
}
311
313
```
312
314
@@ -406,6 +408,75 @@ $cancellation ??= new NullCancellationToken();
406
408
407
409
A `CompositeCancellation` combines multiple independent cancellation objects. If any of these cancellations is cancelled, the `CompositeCancellation` itself will be cancelled.
408
410
411
+
### Utilities
412
+
413
+
Several utility functions and classes are also included in this library.
0 commit comments