Skip to content

Commit

Permalink
Merge pull request #1 from Vinceveve/feature/2.0
Browse files Browse the repository at this point in the history
Switch to rxphp 2
  • Loading branch information
davidwdan authored Apr 18, 2018
2 parents b54373f + a328cfc commit a620636
Show file tree
Hide file tree
Showing 12 changed files with 69 additions and 82 deletions.
52 changes: 41 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,47 @@
language: php
sudo: required

php:
- 5.6
- 7
- hhvm

matrix:
allow_failures:
- php: hhvm
include:
- php: 7.0
env:
- qaExtended=true
- php: 7.1
- php: 7.2
env:
- dropPlatform=false
- php: nightly
env:
- dropPlatform=false
- php: 7.0
env:
- dependencies=lowest
- php: 7.1
env:
- dependencies=lowest
- php: 7.2
env:
- dependencies=lowest
- dropPlatform=false
- php: nightly
env:
- dependencies=lowest
- dropPlatform=false
- php: 7.0
env:
- dependencies=highest
- php: 7.1
env:
- dependencies=highest
- php: 7.2
env:
- dependencies=highest
- dropPlatform=false
- php: nightly
env:
- dependencies=highest
- dropPlatform=false

install:
- composer install
before_script: composer install

script:
- phpunit
- vendor/bin/phpunit
16 changes: 14 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,20 @@
"src/functions.php"
]
},
"autoload-dev": {
"psr-4": {
"Rx\\React\\Tests\\": "tests/",
"Rx\\": "vendor/reactivex/rxphp/test/Rx"
},
"files": [
"vendor/reactivex/rxphp/test/helper-functions.php"
]
},
"require": {
"reactivex/rxphp": "^1.0",
"voryx/event-loop": "^0.2.0"
"reactivex/rxphp": "^2.0",
"voryx/event-loop": "^2.0 || ^3.0"
},
"require-dev": {
"phpunit/phpunit": "^6.0"
}
}
4 changes: 1 addition & 3 deletions examples/delay_foreach.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@

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


$source = \Rx\Observable::range(0, 5)->delay(1000);

$generator = \Rx\await($source);


foreach ($generator as $item) {
echo $item, PHP_EOL;
}

echo "DONE";
echo 'DONE';
6 changes: 1 addition & 5 deletions examples/delay_next.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
<?php

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


$source = \Rx\Observable::range(0, 5)->delay(1000);

/** @var Generator $generator */
$generator = \Rx\await($source);


echo $generator->current(), PHP_EOL; //0

$generator->next();
Expand All @@ -23,5 +20,4 @@
$generator->next();
echo $generator->current(), PHP_EOL; //4


echo "DONE";
echo 'DONE';
8 changes: 1 addition & 7 deletions examples/errors.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

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


$source = \Rx\Observable::error(new Exception('some error'));

$generator = \Rx\await($source);
Expand All @@ -12,10 +11,5 @@
echo $item, PHP_EOL;
}
} catch (\Exception $e) {
echo "caught error: ", $e->getMessage();
echo 'caught error: ', $e->getMessage();
}





11 changes: 5 additions & 6 deletions examples/httpGet.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

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

$terms = ["rxphp", "php", "make php great again"];
$terms = ['rxphp', 'php', 'make php great again'];
$search = \Rx\Observable::fromArray($terms)
->map(function ($term) {
return urlencode($term);
Expand All @@ -13,19 +13,18 @@
return \Rx\React\Http::get("http://www.google.com/search?q={$term}")
->map(function ($result) use ($term) {
return [
"term" => $term,
"page" => $result
'term' => $term,
'page' => $result
];
});
});


$generator = \Rx\await($search);

echo "BLOCKING", PHP_EOL;
echo 'BLOCKING', PHP_EOL;

foreach ($generator as $item) {
echo "Result page for: {$item['term']}", PHP_EOL, $item['page'];
}

echo "DONE";
echo 'DONE';
4 changes: 1 addition & 3 deletions examples/interval.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@

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


$source = \Rx\Observable::interval(1000);

$generator = \Rx\await($source);


foreach ($generator as $item) {
echo $item, PHP_EOL;
}

echo "DONE";
echo 'DONE';
3 changes: 1 addition & 2 deletions examples/interval_take.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

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


$source = \Rx\Observable::interval(1000)
->take(5); //Take the first 5

Expand All @@ -12,4 +11,4 @@
echo $item, PHP_EOL;
}

echo "DONE";
echo 'DONE';
3 changes: 1 addition & 2 deletions examples/interval_timeout.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

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


$source = \Rx\Observable::interval(1000)
->takeUntil(\Rx\Observable::timer(10000)); //timeout after 10 seconds

Expand All @@ -12,4 +11,4 @@
echo $item, PHP_EOL;
}

echo "DONE";
echo 'DONE';
3 changes: 1 addition & 2 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="tests/bootstrap.php">
syntaxCheck="false">
<testsuites>
<testsuite name="Rx/Await">
<directory>tests/</directory>
Expand Down
7 changes: 2 additions & 5 deletions src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use React\EventLoop\LoopInterface;
use Rx\Observer\CallbackObserver;
use Rx\Scheduler\EventLoopScheduler;

/**
* Wait until observable completes.
Expand All @@ -15,14 +14,12 @@
*/
function await(Observable $observable, LoopInterface $loop = null)
{

$completed = false;
$results = [];
$loop = $loop ?: \EventLoop\getLoop();
$scheduler = new EventLoopScheduler($loop);

$observable->subscribe(new CallbackObserver(
function ($value) use (&$results, &$results, $loop) {
function ($value) use (&$results, $loop) {
$results[] = $value;

$loop->stop();
Expand All @@ -35,7 +32,7 @@ function () use (&$completed) {
$completed = true;
}

), $scheduler);
));

while (!$completed) {

Expand Down
34 changes: 0 additions & 34 deletions tests/bootstrap.php

This file was deleted.

0 comments on commit a620636

Please sign in to comment.