Skip to content

Commit af284a8

Browse files
committed
Updated tests to use the correct scheduler
Remove the EventLoopScheduler from all demos
1 parent b3988ba commit af284a8

File tree

81 files changed

+346
-440
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+346
-440
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
RxPHP
22
======
33

4+
## This is the development branch for RxPHP v2 and is not stable. For production, use [v1](https://github.com/reactivex/rxphp) instead.
5+
46
Reactive extensions for PHP. The reactive extensions for PHP are a set of
57
libraries to compose asynchronous and event-based programs using observable
68
collections and LINQ-style query operators in PHP.

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
}
2121
],
2222
"require": {
23-
"php": "~7.1",
23+
"php": "~7.0",
2424
"wyrihaximus/react-async-interop-loop": "dev-master"
2525
},
2626
"require-dev": {

demo/defaultIfEmpty/defaultIfEmpty.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
require_once __DIR__ . '/../bootstrap.php';
44

5-
$source = \Rx\Observable::emptyObservable()->defaultIfEmpty(new \Rx\Observable\ReturnObservable("something"));
5+
$source = \Rx\Observable::emptyObservable()->defaultIfEmpty(Rx\Observable::just('something'));
66

77
$subscription = $source->subscribe($stdoutObserver);

demo/flatMap/flatMap.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
return Rx\Observable::range($value, 2);
99
});
1010

11-
$disposable = $selectManyObservable->subscribe($stdoutObserver);
11+
$selectManyObservable->subscribe($stdoutObserver);

demo/partition/partition.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22

33
require_once __DIR__ . '/../bootstrap.php';
44

5-
$i = new \Rx\Scheduler\ImmediateScheduler();
6-
\Rx\Scheduler::setDefault($i);
7-
8-
list($evens, $odds) = \Rx\Observable::range(0, 10)
5+
list($evens, $odds) = \Rx\Observable::range(0, 10, new \Rx\Scheduler\ImmediateScheduler())
96
->partition(function ($x) {
107
return $x % 2 === 0;
118
});

demo/recursive-scheduler/recursive-scheduler.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,16 @@ public function subscribe(\Rx\ObserverInterface $observer): \Rx\DisposableInterf
3131
$observable = new RecursiveReturnObservable(21);
3232
$disposable = $observable->subscribe($stdoutObserver);
3333

34-
$loop->addPeriodicTimer(0.01, function () {
34+
$loop = \Interop\Async\Loop::get();
35+
36+
$loop->repeat(100, function () {
3537
$memory = memory_get_usage() / 1024;
3638
$formatted = number_format($memory, 3) . 'K';
3739
echo "Current memory usage: {$formatted}\n";
3840
});
3941

4042
// after a second we'll dispose the 21 observable
41-
$loop->addTimer(1.0, function () use ($disposable) {
43+
$loop->delay(1000, function () use ($disposable) {
4244
echo "Disposing 21 observable.\n";
4345
$disposable->dispose();
4446
});

demo/retry/retry.php

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
<?php
22
require_once __DIR__ . '/../bootstrap.php';
33

4-
$loop = \React\EventLoop\Factory::create();
5-
$scheduler = new \Rx\Scheduler\EventLoopScheduler($loop);
6-
74
$count = 0;
85

9-
$observable = Rx\Observable::interval(1000, $scheduler)
6+
$observable = Rx\Observable::interval(1000)
107
->flatMap(function ($x) use (&$count) {
118
if (++$count < 2) {
12-
return Rx\Observable::error(new \Exception("Something"));
9+
return Rx\Observable::error(new \Exception('Something'));
1310
}
1411
return Rx\Observable::just(42);
1512
})
@@ -18,4 +15,3 @@
1815

1916
$observable->subscribe($stdoutObserver);
2017

21-
$loop->run();

demo/retry/retryWhen.php

+2-7
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,16 @@
22

33
require_once __DIR__ . '/../bootstrap.php';
44

5-
$loop = new \React\EventLoop\StreamSelectLoop();
6-
$scheduler = new \Rx\Scheduler\EventLoopScheduler($loop);
7-
85
$source = Rx\Observable::interval(1000)
96
->map(function ($n) {
107
if ($n === 2) {
118
throw new Exception();
129
}
1310
return $n;
1411
})
15-
->retryWhen(function ($errors) {
12+
->retryWhen(function (\Rx\Observable $errors) {
1613
return $errors->delay(200);
1714
})
1815
->take(6);
1916

20-
$subscription = $source->subscribe($createStdoutObserver(), $scheduler);
21-
22-
$loop->run();
17+
$subscription = $source->subscribe($createStdoutObserver());

demo/share/share.php

+1-7
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@
22

33
require_once __DIR__ . '/../bootstrap.php';
44

5-
$loop = \React\EventLoop\Factory::create();
6-
$scheduler = new \Rx\Scheduler\EventLoopScheduler($loop);
7-
85
//With Share
9-
$source = \Rx\Observable::interval(1000, $scheduler)
6+
$source = \Rx\Observable::interval(1000)
107
->take(2)
118
->doOnNext(function ($x) {
129
echo "Side effect\n";
@@ -16,6 +13,3 @@
1613

1714
$published->subscribe($createStdoutObserver('SourceA '));
1815
$published->subscribe($createStdoutObserver('SourceB '));
19-
20-
$loop->run();
21-

demo/share/shareReplay.php

+3-9
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22

33
require_once __DIR__ . '/../bootstrap.php';
44

5-
$loop = \React\EventLoop\Factory::create();
6-
$scheduler = new \Rx\Scheduler\EventLoopScheduler($loop);
7-
85
$interval = Rx\Observable::interval(1000);
96

107
$source = $interval
@@ -16,16 +13,13 @@
1613
$published = $source
1714
->shareReplay(3);
1815

19-
$published->subscribe($createStdoutObserver('SourceA '), $scheduler);
20-
$published->subscribe($createStdoutObserver('SourceB '), $scheduler);
16+
$published->subscribe($createStdoutObserver('SourceA '));
17+
$published->subscribe($createStdoutObserver('SourceB '));
2118

2219
Rx\Observable
2320
::just(true)
2421
->concatMapTo(\Rx\Observable::timer(6000))
2522
->flatMap(function () use ($published) {
2623
return $published;
2724
})
28-
->subscribe($createStdoutObserver('SourceC '), $scheduler);
29-
30-
$loop->run();
31-
25+
->subscribe($createStdoutObserver('SourceC '));

demo/share/shareValue.php

+1-6
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22

33
require_once __DIR__ . '/../bootstrap.php';
44

5-
$loop = \React\EventLoop\Factory::create();
6-
$scheduler = new \Rx\Scheduler\EventLoopScheduler($loop);
7-
8-
$source = \Rx\Observable::interval(1000, $scheduler)
5+
$source = \Rx\Observable::interval(1000)
96
->take(2)
107
->doOnNext(function ($x) {
118
echo "Side effect\n";
@@ -15,5 +12,3 @@
1512

1613
$published->subscribe($createStdoutObserver('SourceA '));
1714
$published->subscribe($createStdoutObserver('SourceB '));
18-
19-
$loop->run();

demo/skip/skipUntil.php

+1-6
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,8 @@
22

33
require_once __DIR__ . '/../bootstrap.php';
44

5-
$loop = \React\EventLoop\Factory::create();
6-
$scheduler = new \Rx\Scheduler\EventLoopScheduler($loop);
7-
85
$observable = Rx\Observable::interval(1000)
96
->skipUntil(\Rx\Observable::timer(5000))
107
->take(3);
118

12-
$observable->subscribe($stdoutObserver, $scheduler);
13-
14-
$loop->run();
9+
$observable->subscribe($stdoutObserver);

demo/switch/switchFirst.php

+1-6
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22

33
require_once __DIR__ . '/../bootstrap.php';
44

5-
$loop = \React\EventLoop\Factory::create();
6-
$scheduler = new \Rx\Scheduler\EventLoopScheduler($loop);
7-
85
$source = Rx\Observable::fromArray([
96
\Rx\Observable::interval(100)->mapTo('a'),
107
\Rx\Observable::interval(200)->mapTo('b'),
@@ -13,6 +10,4 @@
1310
->switchFirst()
1411
->take(3);
1512

16-
$subscription = $source->subscribe($stdoutObserver, $scheduler);
17-
18-
$loop->run();
13+
$subscription = $source->subscribe($stdoutObserver);

demo/throttle/throttle.php

+5-12
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,15 @@
11
<?php
22

3-
use React\EventLoop\Factory;
43
use Rx\Observable;
5-
use Rx\Scheduler\EventLoopScheduler;
64

75
require_once __DIR__ . '/../bootstrap.php';
86

9-
$loop = Factory::create();
10-
$scheduler = new EventLoopScheduler($loop);
11-
127
$times = [
13-
['value' => 0, 'time' => 100],
14-
['value' => 1, 'time' => 600],
8+
['value' => 0, 'time' => 10],
9+
['value' => 1, 'time' => 200],
1510
['value' => 2, 'time' => 400],
16-
['value' => 3, 'time' => 900],
17-
['value' => 4, 'time' => 200]
11+
['value' => 3, 'time' => 500],
12+
['value' => 4, 'time' => 900]
1813
];
1914

2015
// Delay each item by time and project value;
@@ -25,6 +20,4 @@
2520
})
2621
->throttle(300 /* ms */);
2722

28-
$subscription = $source->subscribe($stdoutObserver, $scheduler);
29-
30-
$loop->run();
23+
$subscription = $source->subscribe($stdoutObserver);

demo/throttle/throttle.php.expect

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Next value: 0
2-
Next value: 2
32
Next value: 1
43
Next value: 3
4+
Next value: 4
55
Complete!

demo/timeout/timeout.php

+2-8
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,11 @@
22

33
require_once __DIR__ . '/../bootstrap.php';
44

5-
$loop = new \React\EventLoop\StreamSelectLoop();
6-
7-
$scheduler = new \Rx\Scheduler\EventLoopScheduler($loop);
8-
95
Rx\Observable::interval(1000)
106
->timeout(500)
11-
->subscribe($createStdoutObserver("One second - "), $scheduler);
7+
->subscribe($createStdoutObserver('One second - '));
128

139
Rx\Observable::interval(100)
1410
->take(3)
1511
->timeout(500)
16-
->subscribe($createStdoutObserver("100 ms - "), $scheduler);
17-
18-
$loop->run();
12+
->subscribe($createStdoutObserver('100 ms - '));

demo/timer/timer.php

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
<?php
22
require_once __DIR__ . '/../bootstrap.php';
33

4-
$loop = new \React\EventLoop\StreamSelectLoop();
5-
6-
$scheduler = new \Rx\Scheduler\EventLoopScheduler($loop);
7-
8-
$source = \Rx\Observable::timer(200, $scheduler);
4+
$source = \Rx\Observable::timer(200);
95

106
$source->subscribe($createStdoutObserver());
11-
12-
$loop->run();

demo/timestamp/timestamp.php

+1-7
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@
22

33
require_once __DIR__ . '/../bootstrap.php';
44

5-
$loop = new \React\EventLoop\StreamSelectLoop();
6-
7-
$scheduler = new \Rx\Scheduler\EventLoopScheduler($loop);
8-
9-
$source = \Rx\Observable::interval(1000, $scheduler)
5+
$source = \Rx\Observable::interval(1000)
106
->timestamp()
117
->map(function (\Rx\Timestamped $x) {
128
return $x->getValue() . ':' . $x->getTimestampMillis();
@@ -15,8 +11,6 @@
1511

1612
$source->subscribe($createStdoutObserver());
1713

18-
$loop->run();
19-
2014
// Next value: 0:1460781738354
2115
// Next value: 1:1460781739358
2216
// Next value: 2:1460781740359

demo/zip/zip.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@
2020
function ($array) use ($observer) {
2121
$observer->onNext(json_encode($array));
2222
},
23-
[$observer, "onError"],
24-
[$observer, "onCompleted"]
23+
[$observer, 'onError'],
24+
[$observer, 'onCompleted']
2525
));

0 commit comments

Comments
 (0)