Observable stream vs promise
Showing how streams can be synchronous, whereas promises are always asynchronous
by nickkell
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/rxjs/4.1.0/rx.all.js"></script>
<script src="https://searls.github.io/jasmine-all/jasmine-all-min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bluebird/3.3.4/bluebird.js"></script>
Babel + JSX
describe('rx', () => {
const getObservable = () =>
Rx.Observable.just(true);
it('should allow synchronous behaviour', () => {
let set = false;
getObservable()
.subscribe(value => {
set = value;
});
expect(set).toBe(true);
});
});
describe('bluebird', (done) => {
const getPromise = () =>
Promise.resolve(true);
it('should allow synchronous behaviour', () => {
let set = false;
getPromise()
.then(value => {
set = value;
expect(set).toBe(true);
done();
});
});
});