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


PHP Observable::defer方法代码示例

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


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

示例1: toObservable

 /**
  * Returns an observable sequence that invokes the specified factory function whenever a new observer subscribes.
  *
  * @param callable $factory
  * @return \Rx\Observable\AnonymousObservable
  */
 public static function toObservable(callable $factory)
 {
     $observableFactory = function () use($factory) {
         return Promise::toObservable($factory());
     };
     return Observable::defer($observableFactory);
 }
开发者ID:voryx,项目名称:Rx.PHP,代码行数:13,代码来源:PromiseFactory.php

示例2: refCount_not_connected

 /**
  * @test
  */
 public function refCount_not_connected()
 {
     $disconnected = false;
     $count = 0;
     $xs = Observable::defer(function () use(&$count, &$disconnected) {
         $count++;
         return new AnonymousObservable(function () use(&$disconnected) {
             return new CallbackDisposable(function () use(&$disconnected) {
                 $disconnected = true;
             });
         });
     });
     $subject = new TestSubject();
     $conn = new ConnectableObservable($xs, $subject);
     $refd = $conn->refCount();
     $dis1 = $refd->subscribe(new CallbackObserver());
     $this->assertEquals(1, $count);
     $this->assertEquals(1, $subject->getSubscribeCount());
     $this->assertFalse($disconnected);
     $dis2 = $refd->subscribe(new CallbackObserver());
     $this->assertEquals(1, $count);
     $this->assertEquals(2, $subject->getSubscribeCount());
     $this->assertFalse($disconnected);
     $dis1->dispose();
     $this->assertFalse($disconnected);
     $dis2->dispose();
     $this->assertTrue($disconnected);
     $disconnected = false;
     $dis3 = $refd->subscribe(new CallbackObserver());
     $this->assertEquals(2, $count);
     $this->assertEquals(3, $subject->getSubscribeCount());
     $this->assertFalse($disconnected);
     $dis3->dispose();
     $this->assertTrue($disconnected);
 }
开发者ID:voryx,项目名称:Rx.PHP,代码行数:38,代码来源:PublishTest.php

示例3: toObservable

 /**
  * Converts a Promise to an Observable sequence
  *
  * @param \React\Promise\PromiseInterface $promise
  * @return \Rx\Observable\AnonymousObservable
  */
 public static function toObservable(PromiseInterface $promise)
 {
     return Observable::defer(function () use($promise) {
         $subject = new AsyncSubject();
         $promise->then(function ($value) use($subject) {
             $subject->onNext($value);
             $subject->onCompleted();
         }, [$subject, "onError"]);
         return $subject;
     });
 }
开发者ID:voryx,项目名称:Rx.PHP,代码行数:17,代码来源:Promise.php

示例4: toObservable

 /**
  * Converts a Promise to an Observable sequence
  *
  * @param \React\Promise\PromiseInterface $promise
  * @return \Rx\Observable\AnonymousObservable
  */
 public static function toObservable(PromiseInterface $promise)
 {
     return Observable::defer(function () use($promise) {
         $subject = new AsyncSubject();
         $promise->then(function ($value) use($subject) {
             $subject->onNext($value);
             $subject->onCompleted();
         }, function ($error) use($subject) {
             $error = $error instanceof \Exception ? $error : new RejectedPromiseException($error);
             $subject->onError($error);
         });
         return $subject;
     });
 }
开发者ID:mbonneau,项目名称:RxPHP,代码行数:20,代码来源:Promise.php

示例5: defer_throw

 /**
  * @test
  */
 public function defer_throw()
 {
     $invoked = 0;
     $results = $this->scheduler->startWithCreate(function () use(&$invoked) {
         return Observable::defer(function () use(&$invoked) {
             $invoked++;
             throw new \Exception('error');
         });
     });
     // Note: these tests differ from the RxJS tests that they were based on because RxJS was
     // explicitly using the immediate scheduler on subscribe internally. When we pass the
     // proper scheduler in, the subscription gets scheduled which requires an extra tick.
     $this->assertMessages([onError(201, new \Exception('error'))], $results->getMessages());
     $this->assertEquals(1, $invoked);
 }
开发者ID:voryx,项目名称:Rx.PHP,代码行数:18,代码来源:DeferTest.php

示例6: 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

示例7: defer_error_while_subscribe_with_immediate_scheduler_passes_through

 /**
  * @test
  */
 public function defer_error_while_subscribe_with_immediate_scheduler_passes_through()
 {
     $onErrorCalled = false;
     Observable::defer(function () {
         return Observable::create(function ($observer, $scheduler = null) {
             $observer->onError(new \Exception('I take exception'));
         });
     })->subscribeCallback(null, function (\Exception $e) use(&$onErrorCalled) {
         $onErrorCalled = true;
         $this->assertEquals('I take exception', $e->getMessage());
     }, null, new ImmediateScheduler());
     $this->assertTrue($onErrorCalled);
 }
开发者ID:ReactiveX,项目名称:RxPHP,代码行数:16,代码来源:DeferTest.php

示例8:

<?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

示例9: fromPromise

/**
 * @param PromiseInterface $promise
 * @return Observable
 */
function fromPromise(PromiseInterface $promise)
{
    return Observable::defer(function () use($promise) {
        $subject = new AsyncSubject();
        $promise->then(function ($res) use($subject) {
            $subject->onNext($res);
            $subject->onCompleted();
        }, [$subject, 'onError']);
        return $subject;
    });
}
开发者ID:domraider,项目名称:rxnet,代码行数:15,代码来源:functions.php

示例10: __call

 /**
  * @param $name
  * @param $arguments
  * @return AnonymousObservable
  */
 public function __call($name, array $arguments = [])
 {
     $promise = $this->client->__call($name, $arguments);
     return Observable::defer(function () use($promise) {
         $subject = new AsyncSubject();
         $promise->then(function ($data) use($subject) {
             $subject->onNext($data);
             $subject->onCompleted();
         }, [$subject, "onError"]);
         return $subject;
     });
 }
开发者ID:domraider,项目名称:rxnet,代码行数:17,代码来源:Redis.php


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