All Projects → ReactiveX → Rxphp

ReactiveX / Rxphp

Licence: mit
Reactive extensions for PHP

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to Rxphp

Awesome Rxjs
A collection of awesome RxJS resources
Stars: ✭ 314 (-80.13%)
Mutual labels:  observables, reactivex
zen-signals
☯ The simplest signal library possible
Stars: ✭ 41 (-97.41%)
Mutual labels:  reactivex, observables
Hunch
Hunch provides functions like: All, First, Retry, Waterfall etc., that makes asynchronous flow control more intuitive.
Stars: ✭ 94 (-94.05%)
Mutual labels:  reactivex, asynchronous
Rxgo
Reactive Extensions for the Go language.
Stars: ✭ 3,907 (+147.28%)
Mutual labels:  reactivex, asynchronous
Kirby Imagekit
Asynchronous thumbnail creation and optimization for Kirby 2
Stars: ✭ 109 (-93.1%)
Mutual labels:  asynchronous
Example App
Example app showcasing the ngrx platform
Stars: ✭ 1,361 (-13.86%)
Mutual labels:  observables
Base64 Async
Non-blocking chunked Base64 encoding
Stars: ✭ 98 (-93.8%)
Mutual labels:  asynchronous
React Combinators
[NOT MAINTAINED] Seamless combination of React and reactive programming
Stars: ✭ 95 (-93.99%)
Mutual labels:  observables
Edgedb Python
EdgeDB Python Driver
Stars: ✭ 113 (-92.85%)
Mutual labels:  asynchronous
Async Backplane
Simple, Erlang-inspired fault-tolerance framework for Rust Futures.
Stars: ✭ 113 (-92.85%)
Mutual labels:  asynchronous
Mofuw
mofuw is *MO*re *F*aster, *U*ltra minimal *W*ebserver.
Stars: ✭ 107 (-93.23%)
Mutual labels:  asynchronous
Datastore
🐹 Bloat free and flexible interface for data store and database access.
Stars: ✭ 99 (-93.73%)
Mutual labels:  asynchronous
Index
Metarhia educational program index 📖
Stars: ✭ 2,045 (+29.43%)
Mutual labels:  asynchronous
Oreilly reactive python for data
Resources for the O'Reilly online video "Reactive Python for Data"
Stars: ✭ 98 (-93.8%)
Mutual labels:  reactivex
Tornado Sqlalchemy
SQLAlchemy support for Tornado
Stars: ✭ 112 (-92.91%)
Mutual labels:  asynchronous
Rxstorekit
StoreKit library for RxSwift
Stars: ✭ 96 (-93.92%)
Mutual labels:  reactivex
Tomorrowland
Lightweight Promises for Swift & Obj-C
Stars: ✭ 106 (-93.29%)
Mutual labels:  asynchronous
Aiormq
Pure python AMQP 0.9.1 asynchronous client library
Stars: ✭ 112 (-92.91%)
Mutual labels:  asynchronous
Restbed
Corvusoft's Restbed framework brings asynchronous RESTful functionality to C++14 applications.
Stars: ✭ 1,551 (-1.84%)
Mutual labels:  asynchronous
Mcsniperpy
Minecraft name sniper written in python.
Stars: ✭ 98 (-93.8%)
Mutual labels:  asynchronous

RxPHP

Reactive extensions for PHP. The reactive extensions for PHP are a set of libraries to compose asynchronous and event-based programs using observable collections and LINQ-style query operators in PHP.

CI status Coverage Status

note: This repo is for v2.x, the latest version of RxPHP, not v1.x.

Example

$source = \Rx\Observable::fromArray([1, 2, 3, 4]);

$source->subscribe(
    function ($x) {
        echo 'Next: ', $x, PHP_EOL;
    },
    function (Exception $ex) {
        echo 'Error: ', $ex->getMessage(), PHP_EOL;
    },
    function () {
        echo 'Completed', PHP_EOL;
    }
);

//Next: 1
//Next: 2
//Next: 3
//Next: 4
//Completed

Try out the demos

$ git clone https://github.com/ReactiveX/RxPHP.git
$ cd RxPHP
$ composer install
$ php demo/interval/interval.php

Have fun running the demos in /demo.

note: When running the demos, the scheduler is automatically bootstrapped. When using RxPHP within your own project, you'll need to set the default scheduler.

Installation

  1. Install an event loop. Any event loop should work, but the ReactPHP event loop is recommended.
$ composer require react/event-loop
  1. Install RxPHP using composer.
$ composer require reactivex/rxphp
  1. Write some code.
<?php

require_once __DIR__ . '/vendor/autoload.php';

use Rx\Observable;
use React\EventLoop\Factory;
use Rx\Scheduler;

$loop = Factory::create();

//You only need to set the default scheduler once
Scheduler::setDefaultFactory(function() use($loop){
    return new Scheduler\EventLoopScheduler($loop);
});

Observable::interval(1000)
    ->take(5)
    ->flatMap(function ($i) {
        return Observable::of($i + 1);
    })
    ->subscribe(function ($e) {
        echo $e, PHP_EOL;
    });

$loop->run();

Working with Promises

Some async PHP frameworks have yet to fully embrace the awesome power of observables. To help ease the transition, RxPHP has built in support for ReactPHP promises.

Mixing a promise into an observable stream:

Observable::interval(1000)
    ->flatMap(function ($i) {
        return Observable::fromPromise(\React\Promise\resolve(42 + $i));
    })
    ->subscribe(function ($v) {
        echo $v . PHP_EOL;
    });

Converting an Observable into a promise. (This is useful for libraries that use generators and coroutines):

$observable = Observable::interval(1000)
    ->take(10)
    ->toArray()
    ->map('json_encode');

$promise = $observable->toPromise();

Additional Information

License

RxPHP is licensed under the MIT License - see the LICENSE file for details

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].