PHPackages                             moebius/coroutine - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. moebius/coroutine

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

moebius/coroutine
=================

Easy to use coroutines for PHP.

1.0.102(3y ago)586316MITPHP

Since Apr 5Pushed 3y ago1 watchersCompare

[ Source](https://github.com/moebiusphp/coroutine)[ Packagist](https://packagist.org/packages/moebius/coroutine)[ RSS](/packages/moebius-coroutine/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (4)Versions (42)Used By (6)

moebius/coroutine
=================

[](#moebiuscoroutine)

True "green threads" (coroutines) for PHP 8.1. No plugins needed. Coroutines are like multitasking, but without many of the subtle problems that come from threads.

Compatability
-------------

[](#compatability)

Moebius runs other event loops cooperatively; if you are using React, Moebius will run the React Event loop, if you are using Amp, Moebius will run the Amp event loop.

> TIP! To make compatible event-loop based applications, you can implement against the moebius/loop implementation yourself.

Essentials
----------

[](#essentials)

A coroutine is a function which runs in parallel with other code in your application. You can work with coroutines the same way you work with promises in frameworks like React or Amp. In fact, you can use most promise based libraries with Moebius.

### Conceals the promises

[](#conceals-the-promises)

The main purpose of moebius is to conceal the existence of promises; you should not have to think about coroutines being a part of your application. The only time you need to think about coroutines, is when you need to do multiple things in parallell.

Moebius allows your application to handle multiple requests in parallel, but your program flow should not have to worry about that.

### A Coroutine is a Promise

[](#a-coroutine-is-a-promise)

When you create a coroutine, you get a promise about a future result. That future result can be accessed via the `then()` method, just like any other promise object you're used to.

```
