1
0
mirror of https://github.com/danog/amp.git synced 2024-12-02 17:37:50 +01:00
amp/docs/index.md

43 lines
1.7 KiB
Markdown
Raw Normal View History

---
2021-12-03 00:09:53 +01:00
layout: "docs"
title: "Introduction"
permalink: "/"
---
2021-12-03 00:09:53 +01:00
Amp is a set of seamlessly integrated concurrency libraries for PHP based on [Revolt](https://revolt.run/). This package
provides futures and cancellations as a base for asynchronous programming.
2017-05-26 21:42:33 +02:00
2021-12-03 00:09:53 +01:00
Amp makes heavy use of fibers shipped with PHP 8.1 to write asynchronous code just like synchronous, blocking code. In
contrast to earlier versions, there's no need for generator based coroutines or callbacks. Similar to threads, each
fiber has its own call stack, but fibers are scheduled cooperatively by the event loop. Use `Amp\async()` to run things
concurrently.
2017-05-26 21:42:33 +02:00
## Installation
2021-12-03 00:09:53 +01:00
This package can be installed as a [Composer](https://getcomposer.org/) dependency.
```bash
2017-05-26 21:42:33 +02:00
composer require amphp/amp
```
2021-12-03 00:09:53 +01:00
If you use this library, it's very likely you want to schedule events using [Revolt's event loop](https://revolt.run),
which you should require separately, even if it's automatically installed as a dependency.
```bash
composer require revolt/event-loop
```
2017-05-26 21:42:33 +02:00
## Preamble
2021-12-03 00:09:53 +01:00
The weak link when managing concurrency is humans; we simply don't think asynchronously or in parallel. Instead, we're
very good at doing one thing at a time and the world around us generally fits this model. So to effectively design for
concurrent processing in our code we have a couple of options:
1. Get smarter (not feasible);
2. Abstract concurrent task execution to make it feel synchronous.
2017-05-26 21:42:33 +02:00
## Contents
2021-12-03 00:09:53 +01:00
Amp provides [futures](./futures/README.md) and [cancellations](./cancellation/README.md) as building blocks for
(partially and fully) asynchronous libraries and applications. [Coroutines](./coroutines/README.md) make asynchronous
code feel as synchronous code.