-
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.
Merge pull request #3 from voryx/2.0
Updated to RxPHP v2
- Loading branch information
Showing
22 changed files
with
406 additions
and
431 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,9 +3,10 @@ sudo: required | |
|
||
php: | ||
- 7 | ||
- 7.1 | ||
|
||
install: | ||
- composer install | ||
|
||
script: | ||
- phpunit | ||
- vendor/bin/phpunit |
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 |
---|---|---|
|
@@ -27,17 +27,34 @@ | |
"Rx\\Thruway\\": "src/" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"Rx\\Thruway\\Tests\\": "tests/", | ||
"Rx\\": "vendor/reactivex/rxphp/test/Rx" | ||
}, | ||
"files": [ | ||
"vendor/reactivex/rxphp/test/helper-functions.php" | ||
] | ||
}, | ||
"require": { | ||
"reactivex/rxphp": "^1.4.1", | ||
"voryx/thruway-common": "^1.0.0", | ||
"php": "^7.0", | ||
"voryx/thruway-common": "^1.0.0", | ||
"ratchet/pawl": "^0.2.2", | ||
"voryx/event-loop": "^0.2.0" | ||
"voryx/event-loop": "^2.0.1", | ||
"reactivex/rxphp": "^2.0" | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "^5.5" | ||
}, | ||
"repositories": [ | ||
{ | ||
"type": "vcs", | ||
"url": "[email protected]:voryx/ThruwayCommon.git" | ||
} | ||
] | ||
], | ||
"extra": { | ||
"branch-alias": { | ||
"dev-master": "2.0-dev" | ||
} | ||
} | ||
} |
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
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,25 +1,25 @@ | ||
<?php | ||
|
||
use Rx\Observer\CallbackObserver; | ||
use Rx\Thruway\Client; | ||
|
||
require __DIR__ . '/../vendor/autoload.php'; | ||
|
||
$client = new Client('ws://127.0.0.1:9090', "realm1"); | ||
|
||
$client->register('com.myapp.example', function ($x) { | ||
return \Rx\Observable::interval(300, new \Rx\Scheduler\EventLoopScheduler(\EventLoop\getLoop()))->doOnNext(function () { | ||
echo "."; | ||
}); | ||
}, ["progress" => true])->subscribeCallback( | ||
function () { | ||
echo "Registered ", PHP_EOL; | ||
}, | ||
function (Exception $e) { | ||
echo "Register error: ", $e->getMessage(), PHP_EOL; | ||
}, | ||
function () { | ||
echo "Register completed", PHP_EOL; | ||
} | ||
); | ||
$client | ||
->register('com.myapp.example', function ($x) { | ||
return \Rx\Observable::interval(300)->doOnNext(function () { | ||
echo '.'; | ||
}); | ||
}, ['progress' => true]) | ||
->subscribe( | ||
function () { | ||
echo 'Registered ', PHP_EOL; | ||
}, | ||
function (Exception $e) { | ||
echo 'Register error: ', $e->getMessage(), PHP_EOL; | ||
}, | ||
function () { | ||
echo 'Register completed', PHP_EOL; | ||
}); | ||
|
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,37 +1,37 @@ | ||
<?php | ||
|
||
use Rx\Observer\CallbackObserver; | ||
use Rx\Thruway\Client; | ||
|
||
require __DIR__ . '/../vendor/autoload.php'; | ||
|
||
$client = new Client('ws://127.0.0.1:9090', "realm1"); | ||
$client = new Client('ws://127.0.0.1:9090', 'realm1'); | ||
|
||
$client->registerExtended('com.myapp.example', function ($args, $argskw, $details, $invocationMsg) { | ||
return 1234567; | ||
})->subscribeCallback( | ||
function () { | ||
echo "Registered ", PHP_EOL; | ||
}, | ||
function (Exception $e) { | ||
echo "Register error: ", $e->getMessage(), PHP_EOL; | ||
}, | ||
function () { | ||
echo "Register completed", PHP_EOL; | ||
} | ||
); | ||
$client | ||
->registerExtended('com.myapp.example', function ($args, $argskw, $details, $invocationMsg) { | ||
return 1234567; | ||
}) | ||
->subscribe( | ||
function () { | ||
echo 'Registered ', PHP_EOL; | ||
}, | ||
function (Exception $e) { | ||
echo 'Register error: ', $e->getMessage(), PHP_EOL; | ||
}, | ||
function () { | ||
echo 'Register completed', PHP_EOL; | ||
}); | ||
|
||
$client->call('com.myapp.example', [123], ["foo" => "bar"]) | ||
->subscribe(new CallbackObserver( | ||
function ($res) { | ||
list($args, $argskw, $details) = $res; | ||
$client | ||
->call('com.myapp.example', [123], ['foo' => 'bar']) | ||
->subscribe( | ||
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; | ||
}) | ||
); | ||
echo 'Call result: ', $args[0], PHP_EOL; | ||
}, | ||
function (Exception $e) { | ||
echo 'Call error: ', $e->getMessage(), PHP_EOL; | ||
}, | ||
function () { | ||
echo 'Call completed', PHP_EOL; | ||
}); |
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,24 +1,23 @@ | ||
<?php | ||
|
||
use Rx\Observer\CallbackObserver; | ||
use Rx\Thruway\Client; | ||
|
||
require __DIR__ . '/../vendor/autoload.php'; | ||
|
||
$client = new Client('ws://127.0.0.1:9090', "realm1"); | ||
$client = new Client('ws://127.0.0.1:9090', 'realm1'); | ||
|
||
$client->progressiveCall('com.myapp.example', [1234], []) | ||
// ->take(10) | ||
->subscribe(new CallbackObserver( | ||
function ($res) { | ||
list($args, $argskw, $details) = $res; | ||
$client | ||
->progressiveCall('com.myapp.example', [1234], []) | ||
->take(10) | ||
->subscribe( | ||
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; | ||
}) | ||
); | ||
echo 'Call result: ', $args[0], PHP_EOL; | ||
}, | ||
function (Exception $e) { | ||
echo 'Call error: ', $e->getMessage(), PHP_EOL; | ||
}, | ||
function () { | ||
echo 'Call completed', PHP_EOL; | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
use Rx\Observable; | ||
use Rx\Thruway\Client; | ||
|
||
require __DIR__ . '/../vendor/autoload.php'; | ||
|
||
$client = new Client('ws://127.0.0.1:9090', "realm1"); | ||
|
||
//$source = Observable::interval(1000); | ||
|
||
//$x = $client->publish('com.myapp.hello', $source); | ||
|
||
|
||
$client->register('com.myapp.example', function ($x) { | ||
return $x; | ||
})->subscribe(new \Rx\Observer\CallbackObserver( | ||
function () { | ||
echo "Registered ", PHP_EOL; | ||
}, | ||
function (Exception $e) { | ||
echo "Register error: ", $e->getMessage(), PHP_EOL; | ||
}, | ||
function () { | ||
echo "Register completed", PHP_EOL; | ||
}), new \Rx\Scheduler\EventLoopScheduler(\EventLoop\getLoop()) | ||
|
||
); | ||
|
||
\EventLoop\addTimer(1, function () use ($client) { | ||
echo "a"; | ||
// $client->publish('com.myapp.hello', "hi"); | ||
$client->close(); | ||
}); |
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,35 +1,38 @@ | ||
<?php | ||
|
||
use Rx\Observable; | ||
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()); | ||
$client = new Client('ws://127.0.0.1:9090', 'realm1'); | ||
|
||
|
||
//Repeat only after the proceeding call has completed | ||
$source = $client | ||
->register('com.myapp.example', function () { | ||
return 123; | ||
}) | ||
->mapTo($client->call('com.myapp.example')) | ||
->switchLatest() | ||
->switch() | ||
->take(1) | ||
->timeout(2000) | ||
->repeatWhen(function (\Rx\Observable $attempts) { | ||
->repeatWhen(function (Observable $attempts) { | ||
return $attempts->delay(1000); | ||
}) | ||
->retryWhen(function (\Rx\Observable $errors) { | ||
->retryWhen(function (Observable $errors) { | ||
return $errors->delay(1000); | ||
}); | ||
|
||
$source->subscribe(new \Rx\Observer\CallbackObserver( | ||
$source->subscribe( | ||
function ($res) { | ||
list($args, $argskw, $details) = $res; | ||
|
||
echo "Call result: ", $args[0], PHP_EOL; | ||
echo 'Call result: ', $args[0], PHP_EOL; | ||
}, | ||
function (Exception $e) { | ||
echo "Call error: ", $e->getMessage(), PHP_EOL; | ||
echo 'Call error: ', $e->getMessage(), PHP_EOL; | ||
}, | ||
function () { | ||
echo "Call completed", PHP_EOL; | ||
}), $scheduler); | ||
echo 'Call completed', PHP_EOL; | ||
}); |
Oops, something went wrong.