Skip to content

Commit 73ebcd2

Browse files
committed
Split React Promises from RxPHP
0 parents  commit 73ebcd2

22 files changed

+852
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/composer.lock
2+
/vendor

.travis.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
language: php
2+
sudo: required
3+
4+
php:
5+
- 7
6+
- 7.1
7+
- hhvm
8+
9+
matrix:
10+
allow_failures:
11+
- php: hhvm
12+
13+
install:
14+
- composer install
15+
16+
script:
17+
- phpunit

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2016 Voryx LLC
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# ReactPHP Promises
2+
3+
Provides RxPHP 2 support for ReactPHP's [Promises](https://github.com/reactphp/promise)
4+
5+
RxPHP v2 will only support [async-interop promises](https://github.com/async-interop/promise) by default. This project restores the ReactPHP Promise support found in RxPHP v1.
6+
7+
## Usage
8+
9+
### From Observable
10+
```php
11+
12+
$observable = \Rx\Observable::of(42);
13+
$promise = \Rx\React\Promise::fromObservable($observable);
14+
15+
$promise->then(function ($value) {
16+
echo "Value {$value}\n";
17+
});
18+
19+
```
20+
21+
### To Observable
22+
```php
23+
24+
$promise = \Rx\React\Promise::resolved(42);
25+
$observable = \Rx\React\Promise::toObservable($promise);
26+
27+
$observable->subscribe(function ($value) {
28+
echo "Value {$value}\n";
29+
});
30+
31+
```

composer.json

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"name": "rx/react-promise",
3+
"type": "library",
4+
"description": "RxPHP v2 support for ReactPHP's Promises",
5+
"keywords": [
6+
"rxphp",
7+
"reactivex",
8+
"react",
9+
"reactphp",
10+
"promise",
11+
"rx.php"
12+
],
13+
"license": "MIT",
14+
"authors": [
15+
{
16+
"name": "David Dan",
17+
"email": "davidwdan@gmail.com",
18+
"role": "Developer"
19+
},
20+
{
21+
"name": "Matt Bonneau",
22+
"email": "matt@bonneau.net",
23+
"role": "Developer"
24+
}
25+
],
26+
"autoload": {
27+
"psr-4": {
28+
"Rx\\React\\": "src/"
29+
}
30+
},
31+
"require": {
32+
"react/promise": "~2.2",
33+
"wyrihaximus/react-async-interop-loop": "dev-master",
34+
"reactivex/rxphp": "2.x-dev"
35+
},
36+
"repositories": [
37+
{
38+
"type": "vcs",
39+
"url": "https://github.com/davidwdan/RxPHP.git"
40+
}
41+
]
42+
}

examples/bootstrap.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
/*
4+
* This file is part of RxPHP.
5+
*
6+
* (c) Alexander <iam.asm89@gmail.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
if (file_exists($file = __DIR__.'/../vendor/autoload.php')) {
13+
$autoload = require_once $file;
14+
} else {
15+
throw new RuntimeException('Install dependencies to run test suite.');
16+
}
17+
18+
function asString($value) {
19+
if (is_array($value)) {
20+
return json_encode($value);
21+
}
22+
return (string) $value;
23+
}
24+
25+
$createStdoutObserver = function ($prefix = '') {
26+
return new Rx\Observer\CallbackObserver(
27+
function ($value) use ($prefix) { echo $prefix . "Next value: " . asString($value) . "\n"; },
28+
function ($error) use ($prefix) { echo $prefix . "Exception: " . $error->getMessage() . "\n"; },
29+
function () use ($prefix) { echo $prefix . "Complete!\n"; }
30+
);
31+
};
32+
33+
34+
$stdoutObserver = $createStdoutObserver();

examples/defer.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
require_once __DIR__.'/bootstrap.php';
4+
5+
/* Using a promise */
6+
$source = \Rx\React\PromiseFactory::toObservable(function () {
7+
return \Rx\React\Promise::resolved(42);
8+
});
9+
10+
$subscription = $source->subscribe($createStdoutObserver());
11+
12+
//Next value: 42
13+
//Complete!

examples/defer.php.expect

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Next value: 42
2+
Complete!
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
require_once __DIR__.'/bootstrap.php';
4+
5+
// With React Promise
6+
$source = \Rx\Observable::of(42);
7+
$promise = \Rx\React\Promise::fromObservable($source);
8+
9+
$promise->then(function ($value) {
10+
echo "Value {$value}\n";
11+
});
12+
13+
//Value 42
14+
15+
16+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Value 42

0 commit comments

Comments
 (0)