Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(DeferObservable): add benchmarks & minor perf #1393

Merged
merged 2 commits into from
Apr 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions perf/micro/current-thread-scheduler/observable/defer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
var RxOld = require('rx');
var RxNew = require('../../../../index');

module.exports = function empty(suite) {
var oldObservableWithCurrentThreadScheduler = RxOld.Observable.empty(RxOld.Scheduler.currentThread);
var newObservableWithCurrentThreadScheduler = RxNew.Observable.empty(RxNew.Scheduler.queue);

function oldFactory() { return oldObservableWithCurrentThreadScheduler; }
function newFactory() { return newObservableWithCurrentThreadScheduler; }

var oldDeferWithCurrentThreadScheduler = RxOld.Observable.defer(oldFactory);
var newDeferWithCurrentThreadScheduler = RxNew.Observable.defer(newFactory);

function _next(x) { }
function _error(e) { }
function _complete() { }
// add tests
return suite
.add('old defer with current thread scheduler', function () {
oldDeferWithCurrentThreadScheduler.subscribe(_next, _error, _complete);
})
.add('new defer with current thread scheduler', function () {
newDeferWithCurrentThreadScheduler.subscribe(_next, _error, _complete);
});
};
25 changes: 25 additions & 0 deletions perf/micro/immediate-scheduler/observable/defer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
var RxOld = require('rx');
var RxNew = require('../../../../index');

module.exports = function empty(suite) {
var oldObservableWithImmediateScheduler = RxOld.Observable.empty(RxOld.Scheduler.immediate);
var newObservableWithImmediateScheduler = RxNew.Observable.empty();

function oldFactory() { return oldObservableWithImmediateScheduler; }
function newFactory() { return newObservableWithImmediateScheduler; }

var oldDeferWithImmediateScheduler = RxOld.Observable.defer(oldFactory);
var newDeferWithImmediateScheduler = RxNew.Observable.defer(newFactory);

function _next(x) { }
function _error(e) { }
function _complete() { }
// add tests
return suite
.add('old defer with immediate scheduler', function () {
oldDeferWithImmediateScheduler.subscribe(_next, _error, _complete);
})
.add('new defer with immediate scheduler', function () {
newDeferWithImmediateScheduler.subscribe(_next, _error, _complete);
});
};
12 changes: 8 additions & 4 deletions src/observable/DeferObservable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,16 @@ class DeferSubscriber<T> extends OuterSubscriber<T, T> {

private tryDefer(): void {
try {
const result = this.factory.call(this);
if (result) {
this.add(subscribeToResult(this, result));
}
this._callFactory();
} catch (err) {
this._error(err);
}
}

private _callFactory(): void {
const result = this.factory();
if (result) {
this.add(subscribeToResult(this, result));
}
}
}