当前位置: 首页>>代码示例>>PHP>>正文


PHP Observable::just方法代码示例

本文整理汇总了PHP中Rx\Observable::just方法的典型用法代码示例。如果您正苦于以下问题:PHP Observable::just方法的具体用法?PHP Observable::just怎么用?PHP Observable::just使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Rx\Observable的用法示例。


在下文中一共展示了Observable::just方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: __invoke

 /**
  * @inheritDoc
  */
 public function __invoke(ObservableInterface $observable, ObserverInterface $observer, SchedulerInterface $scheduler = null)
 {
     if ($this->scheduler !== null) {
         $scheduler = $this->scheduler;
     }
     $innerDisp = new SerialDisposable();
     $disp = $observable->subscribe(new CallbackObserver(function ($x) use($innerDisp, $observer, $scheduler) {
         $now = $scheduler->now();
         if ($this->nextSend <= $now) {
             $innerDisp->setDisposable(new EmptyDisposable());
             $observer->onNext($x);
             $this->nextSend = $now + $this->throttleTime - 1;
             return;
         }
         $newDisp = Observable::just($x)->delay($this->nextSend - $now)->subscribe(new CallbackObserver(function ($x) use($observer, $scheduler) {
             $observer->onNext($x);
             $this->nextSend = $scheduler->now() + $this->throttleTime - 1;
             if ($this->completed) {
                 $observer->onCompleted();
             }
         }, [$observer, 'onError']), $scheduler);
         $innerDisp->setDisposable($newDisp);
     }, function (\Exception $e) use($observer, $innerDisp) {
         $innerDisp->dispose();
         $observer->onError($e);
     }, function () use($observer) {
         $this->completed = true;
         if ($this->nextSend === 0) {
             $observer->onCompleted();
         }
     }), $scheduler);
     return new CompositeDisposable([$disp, $innerDisp]);
 }
开发者ID:ReactiveX,项目名称:RxPHP,代码行数:36,代码来源:ThrottleOperator.php

示例2: promise_success

 /**
  * @test
  *
  */
 public function promise_success()
 {
     $source = Observable::just(42);
     $promise = Promise::fromObservable($source);
     $promise->then(function ($value) {
         $this->assertEquals(42, $value);
     }, function () {
         $this->assertTrue(false);
     });
 }
开发者ID:voryx,项目名称:Rx.PHP,代码行数:14,代码来源:PromiseFromObservableTest.php

示例3: connectable_observable_creation

 /**
  * @test
  */
 public function connectable_observable_creation()
 {
     $y = 0;
     $s2 = new Subject();
     $co2 = new ConnectableObservable(Observable::just(1), $s2);
     $co2->subscribe(new CallbackObserver(function ($x) use(&$y) {
         $y = $x;
     }));
     $this->assertNotEquals(1, $y);
     $co2->connect();
     $this->assertEquals(1, $y);
 }
开发者ID:voryx,项目名称:Rx.PHP,代码行数:15,代码来源:ConnectableObservableTest.php

示例4: __invoke

 /**
  * @param \Rx\ObservableInterface $observable
  * @param \Rx\ObserverInterface $observer
  * @param \Rx\SchedulerInterface $scheduler
  * @return \Rx\DisposableInterface
  */
 public function __invoke(ObservableInterface $observable, ObserverInterface $observer, SchedulerInterface $scheduler = null)
 {
     $buffer = "";
     return $observable->defaultIfEmpty(Observable::just(null))->concat(Observable::just($this->delimiter))->concatMap(function ($x) use(&$buffer) {
         if ($x === null || $buffer === null) {
             $buffer = null;
             return Observable::emptyObservable();
         }
         $items = explode($this->delimiter, $buffer . $x);
         $buffer = array_pop($items);
         return Observable::fromArray($items);
     })->subscribe($observer, $scheduler);
 }
开发者ID:RxPHP,项目名称:RxOperatorExtras,代码行数:19,代码来源:CutOperator.php

示例5: findSharePrice

function findSharePrice($symbol)
{
    return Observable::just($symbol)->flatMap(function ($symbol) {
        return Observable::defer(function () use($symbol) {
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_URL, "http://finance.yahoo.com/webservice/v1/symbols/{$symbol}/usd/quote?format=json");
            $result = curl_exec($ch);
            curl_close($ch);
            return Observable::just($result);
        });
    })->map('json_decode')->map(function ($result) {
        return $result->list->resources[0]->resource->fields->price;
    });
}
开发者ID:luijar,项目名称:fp-php,代码行数:16,代码来源:ch08-rx-defer.php

示例6:

<?php

require_once __DIR__ . '/../bootstrap.php';
$source = \Rx\Observable::defer(function () {
    return \Rx\Observable::just(42);
});
$subscription = $source->subscribe($stdoutObserver);
开发者ID:ReactiveX,项目名称:RxPHP,代码行数:7,代码来源:defer.php

示例7: testRetryWhenInnerEmitsBeforeOuterError

 public function testRetryWhenInnerEmitsBeforeOuterError()
 {
     $xs = $this->createColdObservable([onNext(10, 1), onNext(20, 2), onNext(30, 3), onNext(40, 4), onCompleted(50)]);
     $results = $this->scheduler->startWithDispose(function () use($xs) {
         return $xs->retryWhen(function () {
             return Observable::just(1);
         });
     }, 285);
     $this->assertMessages([onNext(210, 1), onNext(220, 2), onNext(230, 3), onNext(240, 4), onCompleted(250)], $results->getMessages());
     $this->assertSubscriptions([subscribe(200, 250)], $xs->getSubscriptions());
 }
开发者ID:ReactiveX,项目名称:RxPHP,代码行数:11,代码来源:RetryWhenTest.php

示例8: println

<?php

// Chapter 08
// Luis Atencio
require_once '../functions/Combinators.php';
require_once '../../vendor/autoload.php';
require_once 'model/User.php';
require_once 'model/Account.php';
require_once 'common.php';
println('Example 0');
\Rx\Observable::just('Hello World!')->subscribe($stdoutObserver());
println('Example 1');
\Rx\Observable::fromArray([1, 2, 3, 4])->subscribe(new \Rx\Observer\CallbackObserver(function ($x) {
    echo 'Next: ', $x, PHP_EOL;
}, function (Exception $ex) {
    echo 'Error: ', $ex->getMessage(), PHP_EOL;
}, function () {
    echo 'Completed', PHP_EOL;
}));
println('Example 2 Reduce Map Filter with Curry');
$isEven = function ($num) {
    return $num % 2 === 0;
};
$add = function ($x, $y) {
    return $x + $y;
};
$raiseTo = function ($power, $num) {
    return pow($num, $power);
};
$computeSquare = P::curry2($raiseTo)(2);
\Rx\Observable::fromArray([1, 2, 3, 4])->filter($isEven)->map($computeSquare)->reduce($add, 0)->subscribe($stdoutObserver());
开发者ID:luijar,项目名称:fp-php,代码行数:31,代码来源:ch08.php

示例9: testCanCompleteInSubscribeAction

 public function testCanCompleteInSubscribeAction()
 {
     $completed = false;
     $emitted = null;
     Observable::just(1)->skipUntil(Observable::just(1))->subscribeCallback(function ($x) use(&$emitted) {
         if ($emitted !== null) {
             $this->fail("emitted should be null");
         }
         $emitted = $x;
     }, null, function () use(&$completed) {
         $completed = true;
     });
     $this->assertTrue($completed);
     $this->assertEquals(1, $emitted);
 }
开发者ID:ReactiveX,项目名称:RxPHP,代码行数:15,代码来源:SkipUntilTest.php

示例10: concatMap_Then_Complete_Task

 /**
  * @test
  */
 public function concatMap_Then_Complete_Task()
 {
     $xs = Observable::fromArray([4, 3, 2, 1]);
     $results = [];
     $completed = false;
     $xs->concatMap(function ($x, $i) {
         return Observable::just($x + $i);
     })->subscribeCallback(function ($x) use(&$results) {
         $results[] = $x;
     }, function ($e) {
         $this->fail('Should not get an error');
     }, function () use(&$completed) {
         $completed = true;
     });
     $this->assertTrue($completed);
     $this->assertEquals([4, 4, 4, 4], $results);
 }
开发者ID:ReactiveX,项目名称:RxPHP,代码行数:20,代码来源:ConcatMapTest.php

示例11:

<?php

require_once __DIR__ . '/../bootstrap.php';
$source = \Rx\Observable::just(2)->startWith(1);
$subscription = $source->subscribe($stdoutObserver);
开发者ID:ReactiveX,项目名称:RxPHP,代码行数:5,代码来源:startWith.php

示例12: testConcatAllError

 public function testConcatAllError()
 {
     $sources = Observable::fromArray([Observable::just(0), Observable::error(new \Exception()), Observable::just(2), Observable::just(3)]);
     $res = [];
     $error = false;
     $completed = false;
     $sources->concatAll()->subscribeCallback(function ($x) use(&$res) {
         $res[] = $x;
     }, function ($e) use(&$res, &$error) {
         $this->assertEquals([0], $res);
         $error = true;
     }, function () use(&$completed) {
         $completed = true;
     });
     $this->assertTrue($error);
     $this->assertFalse($completed);
 }
开发者ID:ReactiveX,项目名称:RxPHP,代码行数:17,代码来源:ConcatTest.php

示例13: resolve

 /**
  * @param $host
  * @param int $maxRecursion
  * @return Observable\AnonymousObservable with ip address
  */
 public function resolve($host, $maxRecursion = 50)
 {
     // Don't resolve IP
     if (filter_var($host, FILTER_VALIDATE_IP)) {
         return Observable::just($host);
     }
     // Caching
     if (array_key_exists($host, $this->cache)) {
         return Observable::just($this->cache[$host]);
     }
     return $this->lookup($host, 'A')->flatMap(function (Event $event) use($host, $maxRecursion) {
         $ip = Arrays::random($event->data["answers"]);
         if (!$ip) {
             throw new RemoteNotFoundException("Can't resolve {$host}");
         }
         if (!filter_var($ip, FILTER_VALIDATE_IP)) {
             if ($maxRecursion <= 0) {
                 throw new RecursionLimitException();
             }
             return $this->resolve($ip, $maxRecursion - 1);
         }
         $this->cache[$host] = $ip;
         return Observable::just($ip);
     });
 }
开发者ID:domraider,项目名称:rxnet,代码行数:30,代码来源:Dns.php

示例14:

<?php

require_once __DIR__ . '/../bootstrap.php';
$source = \Rx\Observable::just(4)->startWithArray([1, 2, 3]);
$subscription = $source->subscribe($stdoutObserver);
开发者ID:ReactiveX,项目名称:RxPHP,代码行数:5,代码来源:startWithArray.php

示例15: throttle_scheduler_overrides_subscribe_scheduler

 /**
  * @test
  */
 public function throttle_scheduler_overrides_subscribe_scheduler()
 {
     $scheduler = $this->createMock(SchedulerInterface::class);
     $scheduler->expects($this->any())->method('schedule')->willReturn(new EmptyDisposable());
     Observable::just(1)->throttle(100, $scheduler)->subscribeCallback(null, null, null, new ImmediateScheduler());
 }
开发者ID:ReactiveX,项目名称:RxPHP,代码行数:9,代码来源:ThrottleTest.php


注:本文中的Rx\Observable::just方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。