mkusher / react-co
Simple reactphp coroutines
Installs: 4 423
Dependents: 1
Suggesters: 0
Security: 0
Stars: 8
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- react/promise: ^2.4
Requires (Dev)
- react/filesystem: dev-master
- webmozart/assert: ^1.0
This package is not auto-updated.
Last update: 2025-03-01 22:34:10 UTC
README
Simple coroutines for your reactphp applications.
Installation
Use composer to install this package
composer require mkusher/react-co
Coroutines
Don't know what coroutines are? Read this awesome article by Nikita Popov
Examples
Basic example where asyncOp1
and asyncOp2
your asynchronous functions that
return instance of PromiseInterface.
use Mkusher\Co; Co\await(function() { $a = yield asyncOp1(); $b = yield asyncOp2($a); });
await
returns Promise, so that you can wait for all your operatoins to complete like:
use Mkusher\Co; Co\await(function() { $a = yield asyncOp1(); return "10"; })->then(function($result) { echo $result; });
This example will write "10" after executing asyncOp1
.
You can find more examples in examples dir