Coder Social home page Coder Social logo

Test not working about rxphp HOT 2 CLOSED

factormaarten avatar factormaarten commented on May 28, 2024
Test not working

from rxphp.

Comments (2)

mbonneau avatar mbonneau commented on May 28, 2024

I suspect the issue you are having has to do with the scheduler. This library generally works asynchronously, so the Observable::of(42) just schedules the emission of a value and does not emit a value unit the underlying scheduler is run. This means the then callable does not get called until after your assertion is made (again, assuming the scheduler is started at some point).

If you wanted it to work immediately, you can use the ImmediateScheduler:

<?php

require __DIR__ . '/vendor/autoload.php';

$promise = \Rx\Observable::of(42, new \Rx\Scheduler\ImmediateScheduler())->toPromise();

$result = null;

$promise->then(function ($value) use (&$result) {
    $result = $value;
});

echo $result . PHP_EOL;

This can also be set with the global configuration:

\Rx\Scheduler::setDefaultFactory(function () {
    return new \Rx\Scheduler\ImmediateScheduler();
});

$promise = \Rx\Observable::of(42)->toPromise();

Or, if you are intending to be async, you could defer checking the result until the after the value is emitted.

from rxphp.

mbonneau avatar mbonneau commented on May 28, 2024

@mpjraaij I just saw your comment on https://github.com/voryx/PgAsync. If you are using this in conjunction with that, you do not want to use the ImmediateScheduler.

from rxphp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.