Skip to content

Commit

Permalink
feat(AsapScheduler): rename NextTickScheduler to AsapScheduler
Browse files Browse the repository at this point in the history
- NextTickScheduler is now AsapScheduler
- NextTickAction is now AsapAction
- Rx.Scheduler.nextTick is now Rx.Scheduler.asap

This was done to more clearly define in a concise way what the scheduler is doing
if you google 'asap javascript', a library that does the same thing comes up as the
top result.

BREAKING CHANGE: Rx.Scheduler.nextTick is now Rx.Scheduler.asap
closes #838
  • Loading branch information
benlesh committed Dec 8, 2015
1 parent 66eb537 commit 3255fb3
Show file tree
Hide file tree
Showing 20 changed files with 46 additions and 46 deletions.
2 changes: 1 addition & 1 deletion spec/observables/SubscribeOnObservable-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('SubscribeOnObservable', function () {
var e1 = hot('--a--b--|');
var scheduler = new SubscribeOnObservable(e1, 0, jasmine.createSpy('dummy')).scheduler;

expect(scheduler).toBe(Rx.Scheduler.nextTick);
expect(scheduler).toBe(Rx.Scheduler.asap);
});

it('should create observable via staic create function', function () {
Expand Down
2 changes: 1 addition & 1 deletion spec/observables/interval-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('Observable.interval', function () {
it('should specify default scheduler if incorrect scheduler specified', function () {
var scheduler = Observable.interval(10, jasmine.createSpy('dummy')).scheduler;

expect(scheduler).toBe(Rx.Scheduler.nextTick);
expect(scheduler).toBe(Rx.Scheduler.asap);
});

it('should emit when relative interval set to zero', function () {
Expand Down
14 changes: 7 additions & 7 deletions spec/observables/range-spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var Rx = require('../../dist/cjs/Rx');
var RangeObservable = require('../../dist/cjs/observable/range').RangeObservable;
var Observable = Rx.Observable;
var nextTick = Rx.Scheduler.nextTick;
var asap = Rx.Scheduler.asap;

describe('Observable.range', function () {
it('should synchronously create a range of values by default', function () {
Expand All @@ -14,14 +14,14 @@ describe('Observable.range', function () {

it('should accept a scheduler' , function (done) {
var expected = [12, 13, 14, 15];
spyOn(nextTick, 'schedule').and.callThrough();
spyOn(asap, 'schedule').and.callThrough();

var source = Observable.range(12, 4, nextTick);
var source = Observable.range(12, 4, asap);

expect(source.scheduler).toBe(nextTick);
expect(source.scheduler).toBe(asap);

source.subscribe(function (x) {
expect(nextTick.schedule).toHaveBeenCalled();
expect(asap.schedule).toHaveBeenCalled();
var exp = expected.shift();
expect(x).toBe(exp);
}, done.throw, done);
Expand All @@ -36,8 +36,8 @@ describe('RangeObservable', function () {
});

it('should accept a scheduler', function () {
var observable = RangeObservable.create(12, 4, nextTick);
expect(observable.scheduler).toBe(nextTick);
var observable = RangeObservable.create(12, 4, asap);
expect(observable.scheduler).toBe(asap);
});
});

Expand Down
2 changes: 1 addition & 1 deletion spec/subject-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
var Rx = require('../dist/cjs/Rx');

var Subject = Rx.Subject;
var nextTick = Rx.Scheduler.nextTick;
var asap = Rx.Scheduler.asap;
var Observable = Rx.Observable;

describe('Subject', function () {
Expand Down
2 changes: 1 addition & 1 deletion spec/subjects/behavior-subject-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
var Rx = require('../../dist/cjs/Rx');

var BehaviorSubject = Rx.BehaviorSubject;
var nextTick = Rx.Scheduler.nextTick;
var asap = Rx.Scheduler.asap;
var Observable = Rx.Observable;
var ObjectUnsubscribedError = Rx.ObjectUnsubscribedError;

Expand Down
2 changes: 1 addition & 1 deletion spec/subjects/replay-subject-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
var Rx = require('../../dist/cjs/Rx');

var ReplaySubject = Rx.ReplaySubject;
var nextTick = Rx.Scheduler.nextTick;
var asap = Rx.Scheduler.asap;
var Observable = Rx.Observable;

describe('ReplaySubject', function () {
Expand Down
6 changes: 3 additions & 3 deletions src/Rx.KitchenSink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ import {Notification} from './Notification';
import {EmptyError} from './util/EmptyError';
import {ObjectUnsubscribedError} from './util/ObjectUnsubscribedError';
import {ArgumentOutOfRangeError} from './util/ArgumentOutOfRangeError';
import {nextTick} from './scheduler/nextTick';
import {asap} from './scheduler/asap';
import {queue} from './scheduler/queue';
import {NextTickScheduler} from './scheduler/NextTickScheduler';
import {AsapScheduler} from './scheduler/AsapScheduler';
import {QueueScheduler} from './scheduler/QueueScheduler';
import {TimeInterval} from './operator/extended/timeInterval';
import {TestScheduler} from './testing/TestScheduler';
Expand All @@ -151,7 +151,7 @@ import {rxSubscriber} from './symbol/rxSubscriber';

/* tslint:disable:no-var-keyword */
var Scheduler = {
nextTick,
asap,
queue
};

Expand Down
6 changes: 3 additions & 3 deletions src/Rx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,16 @@ import {Notification} from './Notification';
import {EmptyError} from './util/EmptyError';
import {ArgumentOutOfRangeError} from './util/ArgumentOutOfRangeError';
import {ObjectUnsubscribedError} from './util/ObjectUnsubscribedError';
import {asap} from './scheduler/asap';
import {queue} from './scheduler/queue';
import {nextTick} from './scheduler/nextTick';
import {NextTickScheduler} from './scheduler/NextTickScheduler';
import {AsapScheduler} from './scheduler/AsapScheduler';
import {QueueScheduler} from './scheduler/QueueScheduler';
import {rxSubscriber} from './symbol/rxSubscriber';
/* tslint:enable:no-unused-variable */

/* tslint:disable:no-var-keyword */
var Scheduler = {
nextTick,
asap,
queue
};

Expand Down
8 changes: 4 additions & 4 deletions src/observable/SubscribeOnObservable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import {Scheduler} from '../Scheduler';
import {Subscriber} from '../Subscriber';
import {Subscription} from '../Subscription';
import {Observable} from '../Observable';
import {nextTick} from '../scheduler/nextTick';
import {asap} from '../scheduler/asap';
import {isNumeric} from '../util/isNumeric';

export class SubscribeOnObservable<T> extends Observable<T> {
static create<T>(source: Observable<T>, delay: number = 0, scheduler: Scheduler = nextTick): Observable<T> {
static create<T>(source: Observable<T>, delay: number = 0, scheduler: Scheduler = asap): Observable<T> {
return new SubscribeOnObservable(source, delay, scheduler);
}

Expand All @@ -16,13 +16,13 @@ export class SubscribeOnObservable<T> extends Observable<T> {

constructor(public source: Observable<T>,
private delayTime: number = 0,
private scheduler: Scheduler = nextTick) {
private scheduler: Scheduler = asap) {
super();
if (!isNumeric(delayTime) || delayTime < 0) {
this.delayTime = 0;
}
if (!scheduler || typeof scheduler.schedule !== 'function') {
this.scheduler = nextTick;
this.scheduler = asap;
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/observable/interval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import {Subscriber} from '../Subscriber';
import {isNumeric} from '../util/isNumeric';
import {Scheduler} from '../Scheduler';
import {Observable} from '../Observable';
import {nextTick} from '../scheduler/nextTick';
import {asap} from '../scheduler/asap';

export class IntervalObservable<T> extends Observable<T> {
static create(period: number = 0, scheduler: Scheduler = nextTick): Observable<number> {
static create(period: number = 0, scheduler: Scheduler = asap): Observable<number> {
return new IntervalObservable(period, scheduler);
}

Expand All @@ -23,13 +23,13 @@ export class IntervalObservable<T> extends Observable<T> {
(<any> this).schedule(state, period);
}

constructor(private period: number = 0, private scheduler: Scheduler = nextTick) {
constructor(private period: number = 0, private scheduler: Scheduler = asap) {
super();
if (!isNumeric(period) || period < 0) {
this.period = 0;
}
if (!scheduler || typeof scheduler.schedule !== 'function') {
this.scheduler = nextTick;
this.scheduler = asap;
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/observable/timer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {isNumeric} from '../util/isNumeric';
import {Scheduler} from '../Scheduler';
import {Observable} from '../Observable';
import {nextTick} from '../scheduler/nextTick';
import {asap} from '../scheduler/asap';
import {isScheduler} from '../util/isScheduler';
import {isDate} from '../util/isDate';

Expand Down Expand Up @@ -49,7 +49,7 @@ export class TimerObservable<T> extends Observable<T> {
scheduler = <Scheduler> period;
}
if (!isScheduler(scheduler)) {
scheduler = nextTick;
scheduler = asap;
}
this.scheduler = scheduler;

Expand Down
6 changes: 3 additions & 3 deletions src/operator/bufferTime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ import {Subscriber} from '../Subscriber';
import {Observable} from '../Observable';
import {Scheduler} from '../Scheduler';
import {Action} from '../scheduler/Action';
import {nextTick} from '../scheduler/nextTick';
import {asap} from '../scheduler/asap';

/**
* buffers values from the source for a specific time period. Optionally allows new buffers to be set up at an interval.
* @param {number} the amount of time to fill each buffer for before emitting them and clearing them.
* @param {number} [bufferCreationInterval] the interval at which to start new buffers.
* @param {Scheduler} [scheduler] (optional, defaults to `nextTick` scheduler) The scheduler on which to schedule the
* @param {Scheduler} [scheduler] (optional, defaults to `asap` scheduler) The scheduler on which to schedule the
* intervals that determine buffer boundaries.
* @returns {Observable<T[]>} an observable of arrays of buffered values.
*/
export function bufferTime<T>(bufferTimeSpan: number,
bufferCreationInterval: number = null,
scheduler: Scheduler = nextTick): Observable<T[]> {
scheduler: Scheduler = asap): Observable<T[]> {
return this.lift(new BufferTimeOperator(bufferTimeSpan, bufferCreationInterval, scheduler));
}

Expand Down
4 changes: 2 additions & 2 deletions src/operator/debounceTime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import {Observable} from '../Observable';
import {Subscriber} from '../Subscriber';
import {Scheduler} from '../Scheduler';
import {Subscription} from '../Subscription';
import {nextTick} from '../scheduler/nextTick';
import {asap} from '../scheduler/asap';

export function debounceTime<T>(dueTime: number, scheduler: Scheduler = nextTick): Observable<T> {
export function debounceTime<T>(dueTime: number, scheduler: Scheduler = asap): Observable<T> {
return this.lift(new DebounceTimeOperator(dueTime, scheduler));
}

Expand Down
4 changes: 2 additions & 2 deletions src/operator/sampleTime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import {Observable} from '../Observable';
import {Operator} from '../Operator';
import {Subscriber} from '../Subscriber';
import {Scheduler} from '../Scheduler';
import {nextTick} from '../scheduler/nextTick';
import {asap} from '../scheduler/asap';

export function sampleTime<T>(delay: number, scheduler: Scheduler = nextTick): Observable<T> {
export function sampleTime<T>(delay: number, scheduler: Scheduler = asap): Observable<T> {
return this.lift(new SampleTimeOperator(delay, scheduler));
}

Expand Down
4 changes: 2 additions & 2 deletions src/operator/throttleTime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import {Operator} from '../Operator';
import {Subscriber} from '../Subscriber';
import {Scheduler} from '../Scheduler';
import {Subscription} from '../Subscription';
import {nextTick} from '../scheduler/nextTick';
import {asap} from '../scheduler/asap';

export function throttleTime<T>(delay: number, scheduler: Scheduler = nextTick) {
export function throttleTime<T>(delay: number, scheduler: Scheduler = asap) {
return this.lift(new ThrottleTimeOperator(delay, scheduler));
}

Expand Down
4 changes: 2 additions & 2 deletions src/operator/windowTime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import {Observable} from '../Observable';
import {Subject} from '../Subject';
import {Scheduler} from '../Scheduler';
import {Action} from '../scheduler/Action';
import {nextTick} from '../scheduler/nextTick';
import {asap} from '../scheduler/asap';

export function windowTime<T>(windowTimeSpan: number,
windowCreationInterval: number = null,
scheduler: Scheduler = nextTick): Observable<Observable<T>> {
scheduler: Scheduler = asap): Observable<Observable<T>> {
return this.lift(new WindowTimeOperator(windowTimeSpan, windowCreationInterval, scheduler));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {Immediate} from '../util/Immediate';
import {QueueAction} from './QueueAction';
import {Action} from './Action';

export class NextTickAction<T> extends QueueAction<T> {
export class AsapAction<T> extends QueueAction<T> {
private id: any;

schedule(state?: any): Action {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {QueueScheduler} from './QueueScheduler';
import {Subscription} from '../Subscription';
import {Action} from './Action';
import {NextTickAction} from './NextTickAction';
import {AsapAction} from './AsapAction';
import {QueueAction} from './QueueAction';

export class NextTickScheduler extends QueueScheduler {
export class AsapScheduler extends QueueScheduler {
scheduleNow<T>(work: (x?: any) => Subscription<T>, state?: any): Action {
return (this.scheduled ?
new QueueAction(this, work) :
new NextTickAction(this, work)).schedule(state);
new AsapAction(this, work)).schedule(state);
}
}
3 changes: 3 additions & 0 deletions src/scheduler/asap.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import {AsapScheduler} from './AsapScheduler';

export const asap = new AsapScheduler();
3 changes: 0 additions & 3 deletions src/scheduler/nextTick.ts

This file was deleted.

0 comments on commit 3255fb3

Please sign in to comment.