Amp no longer ships its own event loop. It's now based on Revolt.
Revolt\EventLoop is quite similar to Amp's previous
Amp\Loop. A very important difference is using
float $seconds instead of
int $milliseconds for timers though!
Future is a replacement for the previous
There's no need for callbacks or
await() method is based on fibers and replaces generator based coroutines /
Amp\Future::await()instead, which can be called in any (nested) context unlike before.
Amp\call(): Remove the passed closure boilerplate and all
yieldkeywords, interruption is handled via fibers now instead of generator coroutines.
Amp\asyncCall(): Replace invocations with
Amp\async(), which starts a new fiber instead of using generators.
Amp\coroutine(): There's no direct replacement.
Amp\asyncCoroutine(): There's no direct replacement.
Future::await()accepts an optional
Cancellation, which can be used as a replacement.
Amp\Promise\rethrow(): Unhandled errors are now automatically thrown into the event loop, so there's no need for that function anymore.
- Unhandled errors can be ignored using
Future::ignore()if needed, but should usually be handled in some way.
Amp\now()returning the time in seconds instead of milliseconds.
Amp\delay()to accept the delay in seconds now instead of milliseconds.
Amp\weakClosure()to allow a class to hold a self-referencing Closure without creating a circular reference that prevents automatic garbage collection.
Amp\trapSignal()to await one or multiple signals.
Promise combinators have been renamed:
Amp\Promise\race()has been renamed to
Amp\Promise\first()has been renamed to
Amp\Promise\some()has been renamed to
Amp\Promise\any()has been renamed to
Amp\Promise\all()has been renamed to
CancellationTokenhas been renamed to
CancellationTokenSourcehas been renamed to
NullCancellationTokenhas been renamed to
TimeoutCancellationTokenhas been renamed to
CombinedCancellationTokenhas been renamed to
SignalCancellationhas been added.
Iterators have been removed from
amphp/amp as normal PHP iterators can be used with fibers now and there's no need for a separate API.
However, there's still some need for concurrent iterators, which is covered by the new
amphp/pipeline library now.
Amp\Closable has been added as a new basic interface for closable resources such as streams or sockets.
Strict types now declared in all library files.
This will affect callbacks invoked within this library's code which use scalar types as parameters.
Functions used with
Amp\async() are the most likely to be affected by this change — these functions will now be invoked within a strict-types context.