Comments (2)
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.
@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)
- Promise::fromObservable should be cancelable
- Update PHPUnit to 5.7
- Disposed of scheduled item does not cancel timer in some instances
- EventLoopScheduler does not cancel timer in certain circumstances
- Not getting any output in the console HOT 6
- Weird result for Iterators and Generators and multiple listeners/subscribers HOT 2
- Change behavior when exception occurs in `onNext` HOT 1
- multi-threads support HOT 5
- Observable from function HOT 3
- How to resume on next after catch? HOT 3
- Unexpected Script Execution within PHP 7.3 HOT 8
- Is this still maintained? HOT 1
- When trying to write a test I get 'Error: Call to undefined function Tests\onNext()' HOT 1
- Implement mergeDelayError HOT 2
- PHP 8 Compatibility HOT 4
- Handling streams HOT 1
- Pluck will error on null value
- [ General question ] functional API, RxJS-like HOT 2
- changing behavior of interval function
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rxphp.