Promises in combination with generators are used to build coroutines, which allow writing asynchronous code just like synchronous code, without any callbacks.
Traditionally, PHP has a synchronous execution flow, doing one thing at a time.
If you query a database, you send the query and wait for the response from the database server in a blocking manner.
Once you have the response, you can start doing the next thing.
Instead of sitting there and doing nothing while waiting, we could already send the next database query, or do an HTTP call to an API.
Making use of the time we usually spend on waiting for I/O can speed up the total execution time.
The following diagram shows the execution flow with dependencies between the different tasks, once executed sequentially and once concurrently.
![](docs/images/sequential-vs-concurrent.png)
Amp allows such concurrent I/O operations while keeping the cognitive load low by avoiding callbacks.
Instead, the results of asynchronous operations can be awaited using `yield` resulting in code which is structured like traditional blocking I/O code while the actual execution flow is handled by Amp.
Extensions are only needed if your app necessitates a high numbers of concurrent socket connections, usually this limit is configured up to 1024 file descriptors.
Examples can be found in the [`./examples`](./examples) directory of this repository as well as in the `./examples` directory of [our other libraries](https://github.com/amphp?utf8=%E2%9C%93&q=&type=public&language=php).