-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WIP] Added progressiveCall and progressiveRegister
- Loading branch information
Showing
3 changed files
with
87 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,48 @@ | ||
<?php | ||
|
||
use Rx\Observable; | ||
use Rx\Observer\CallbackObserver; | ||
use Rx\Scheduler\EventLoopScheduler; | ||
use Rx\Thruway\Client; | ||
|
||
require __DIR__ . '/../vendor/autoload.php'; | ||
|
||
$client = new \Rx\Thruway\Client("ws://127.0.0.1:9090", "realm1"); | ||
$scheduler = new \Rx\Scheduler\EventLoopScheduler(\EventLoop\getLoop()); | ||
|
||
$source = $client | ||
->register('com.myapp.example', function () { | ||
return \Rx\Observable::fromArray([1, 2, 3, 4]); | ||
}, ["progress" => true]) | ||
->flatMapTo($client->call('com.myapp.example', [], [], ["receive_progress" => true]) | ||
->repeatWhen(function (\Rx\Observable $attempts) { | ||
return $attempts->delay(1000); | ||
}) | ||
); | ||
|
||
$source->subscribe(new \Rx\Observer\CallbackObserver( | ||
function ($res) { | ||
list($args, $argskw, $details) = $res; | ||
|
||
echo "Call result: ", $args[0], PHP_EOL; | ||
}, | ||
function (Exception $e) { | ||
echo "Call error: ", $e->getMessage(), PHP_EOL; | ||
}, | ||
function () { | ||
echo "Call completed", PHP_EOL; | ||
}), $scheduler); | ||
$client = new Client("ws://127.0.0.1:9090", "realm1"); | ||
$scheduler = new EventLoopScheduler(\EventLoop\getLoop()); | ||
|
||
$client->progressiveRegister('com.myapp.example', function () { | ||
return Observable::interval(500); | ||
})->subscribe(new CallbackObserver(), $scheduler); | ||
|
||
|
||
$client->progressiveCall('com.myapp.example', [], []) | ||
->take(5) | ||
->repeatWhen(function (Observable $attempts) { | ||
return $attempts->delay(1000)->take(1); | ||
}) | ||
->subscribe(new CallbackObserver( | ||
function ($res) { | ||
list($args, $argskw, $details) = $res; | ||
|
||
echo "Call result: ", $args[0], PHP_EOL; | ||
}, | ||
function (Exception $e) { | ||
echo "Call error: ", $e->getMessage(), PHP_EOL; | ||
}, | ||
function () { | ||
echo "Call completed", PHP_EOL; | ||
}), $scheduler); | ||
|
||
|
||
//Output | ||
//Call result: 0 | ||
//Call result: 1 | ||
//Call result: 2 | ||
//Call result: 3 | ||
//Call result: 4 | ||
//Call result: 0 | ||
//Call result: 1 | ||
//Call result: 2 | ||
//Call result: 3 | ||
//Call result: 4 | ||
//Call completed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters