From da2b4692ca1e05578b67191d012e36a8b424f8ad Mon Sep 17 00:00:00 2001 From: Matt Bonneau Date: Thu, 19 Apr 2018 17:59:03 -0400 Subject: [PATCH] Added example to README.md and touched up url_list.txt --- README.md | 24 ++++++++++++++++++++++++ examples/url_list.txt | 6 +++--- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index c0cbd68..b0bf623 100644 --- a/README.md +++ b/README.md @@ -23,3 +23,27 @@ It bootstraps a swoole scheduler for you, so you can do things like: ``` +## Use with other Swoole modules + +A small number of Swoole modules have helper Rx wrappers in this library. +You can use these to combine into more complex examples: +```php + +// this example uses the rx/operator-extras package for `cut` + +$file = \Rx\Swoole\Async::read(__DIR__ . '/url_list.txt'); + +$urlInfo = $file + ->cut("\n") + ->flatMap(function ($url) { + return \Rx\Swoole\Http::get($url) + ->map(function ($content) use ($url) { + return $url . " is " . strlen($content) . " bytes.\n"; + }); + }); + +$urlInfo->subscribe(function ($info) { + echo $info; + }); +``` + diff --git a/examples/url_list.txt b/examples/url_list.txt index c96ed45..ea108cf 100644 --- a/examples/url_list.txt +++ b/examples/url_list.txt @@ -1,3 +1,3 @@ -https://www.google.com:80/ -https://www.facebook.com:80/ -https://www.microsoft.com:80/ \ No newline at end of file +https://www.google.com/ +https://www.facebook.com/ +https://www.microsoft.com/ \ No newline at end of file