Skip to content
This repository was archived by the owner on Apr 20, 2018. It is now read-only.

Commit 08f8c84

Browse files
Adding throttleFirst for Issue #352
1 parent 38e4c33 commit 08f8c84

25 files changed

+392
-10
lines changed

Gruntfile.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ var browsers = [{
292292
'src/core/linq/observable/skipwithtime.js',
293293
'src/core/linq/observable/skipuntilwithtime.js',
294294
'src/core/linq/observable/takeuntilwithtime.js',
295+
'src/core/linq/observable/throttlefirst.js',
295296

296297
// Transducers
297298
'src/core/linq/observable/transduce.js',
@@ -564,6 +565,7 @@ var browsers = [{
564565
'src/core/linq/observable/skipwithtime.js',
565566
'src/core/linq/observable/skipuntilwithtime.js',
566567
'src/core/linq/observable/takeuntilwithtime.js',
568+
'src/core/linq/observable/throttlefirst.js',
567569

568570
// Experimental Flattening
569571
'src/core/linq/observable/exclusive.js',
@@ -972,6 +974,7 @@ var browsers = [{
972974
'src/core/linq/observable/timestamp.js', // timeoutScheduler, select
973975
'src/core/linq/observable/sample.js', // AnonymousObservable, CompositeDisposable, interval, timeoutScheduler
974976
'src/core/linq/observable/timeout.js', // AnonymousObservable, timeoutScheduler, throw, SingleAssignmentDisposable, SerialDisposable, CompositeDisposable
977+
'src/core/linq/observable/throttlefirst.js',
975978

976979
// Backpressure operators
977980
'src/core/backpressure/pausable.js',
@@ -1124,6 +1127,7 @@ var browsers = [{
11241127
'src/core/linq/observable/timestamp.js', // timeoutScheduler, select
11251128
'src/core/linq/observable/sample.js', // AnonymousObservable, CompositeDisposable, interval, timeoutScheduler
11261129
'src/core/linq/observable/timeout.js', // AnonymousObservable, timeoutScheduler, throw, SingleAssignmentDisposable, SerialDisposable, CompositeDisposable
1130+
'src/core/linq/observable/throttlefirst.js',
11271131

11281132
// Backpressure operators
11291133
'src/core/backpressure/pausable.js',
@@ -1418,6 +1422,7 @@ var browsers = [{
14181422
'src/core/linq/observable/skipwithtime.js',
14191423
'src/core/linq/observable/skipuntilwithtime.js',
14201424
'src/core/linq/observable/takeuntilwithtime.js',
1425+
'src/core/linq/observable/throttlefirst.js',
14211426
'src/core/suboutro.js'
14221427
],
14231428
dest: 'dist/rx.time.js'

dist/rx.all.compat.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8643,6 +8643,33 @@ if (!Array.prototype.forEach) {
86438643
});
86448644
};
86458645

8646+
/**
8647+
* Returns an Observable that emits only the first item emitted by the source Observable during sequential time windows of a specified duration.
8648+
* @param {Number} windowDuration time to wait before emitting another item after emitting the last item
8649+
* @param {Scheduler} [scheduler] the Scheduler to use internally to manage the timers that handle timeout for each item. If not provided, defaults to Scheduler.timeout.
8650+
* @returns {Observable} An Observable that performs the throttle operation.
8651+
*/
8652+
observableProto.throttleFirst = function (windowDuration, scheduler) {
8653+
isScheduler(scheduler) || (scheduler = timeoutScheduler);
8654+
var duration = +windowDuration || 0;
8655+
if (duration <= 0) { throw new RangeError('windowDuration cannot be less or equal zero.'); }
8656+
var source = this;
8657+
return new AnonymousObservable(function (observer) {
8658+
var lastOnNext = 0;
8659+
return source.subscribe(
8660+
function (x) {
8661+
var now = scheduler.now();
8662+
if (lastOnNext === 0 || now - lastOnNext >= duration) {
8663+
lastOnNext = now;
8664+
observer.onNext(x);
8665+
}
8666+
},
8667+
observer.onError.bind(observer),
8668+
observer.onCompleted.bind(observer)
8669+
);
8670+
});
8671+
};
8672+
86468673
/*
86478674
* Performs a exclusive waiting for the first to finish before subscribing to another observable.
86488675
* Observables that come in between subscriptions will be dropped on the floor.

dist/rx.all.compat.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/rx.all.compat.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/rx.all.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8424,6 +8424,33 @@
84248424
});
84258425
};
84268426

8427+
/**
8428+
* Returns an Observable that emits only the first item emitted by the source Observable during sequential time windows of a specified duration.
8429+
* @param {Number} windowDuration time to wait before emitting another item after emitting the last item
8430+
* @param {Scheduler} [scheduler] the Scheduler to use internally to manage the timers that handle timeout for each item. If not provided, defaults to Scheduler.timeout.
8431+
* @returns {Observable} An Observable that performs the throttle operation.
8432+
*/
8433+
observableProto.throttleFirst = function (windowDuration, scheduler) {
8434+
isScheduler(scheduler) || (scheduler = timeoutScheduler);
8435+
var duration = +windowDuration || 0;
8436+
if (duration <= 0) { throw new RangeError('windowDuration cannot be less or equal zero.'); }
8437+
var source = this;
8438+
return new AnonymousObservable(function (observer) {
8439+
var lastOnNext = 0;
8440+
return source.subscribe(
8441+
function (x) {
8442+
var now = scheduler.now();
8443+
if (lastOnNext === 0 || now - lastOnNext >= duration) {
8444+
lastOnNext = now;
8445+
observer.onNext(x);
8446+
}
8447+
},
8448+
observer.onError.bind(observer),
8449+
observer.onCompleted.bind(observer)
8450+
);
8451+
});
8452+
};
8453+
84278454
/**
84288455
* Executes a transducer to transform the observable sequence
84298456
* @param {Transducer} transducer A transducer to execute

dist/rx.all.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/rx.all.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/rx.lite.compat.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4217,6 +4217,33 @@ if (!Array.prototype.forEach) {
42174217
});
42184218
};
42194219

4220+
/**
4221+
* Returns an Observable that emits only the first item emitted by the source Observable during sequential time windows of a specified duration.
4222+
* @param {Number} windowDuration time to wait before emitting another item after emitting the last item
4223+
* @param {Scheduler} [scheduler] the Scheduler to use internally to manage the timers that handle timeout for each item. If not provided, defaults to Scheduler.timeout.
4224+
* @returns {Observable} An Observable that performs the throttle operation.
4225+
*/
4226+
observableProto.throttleFirst = function (windowDuration, scheduler) {
4227+
isScheduler(scheduler) || (scheduler = timeoutScheduler);
4228+
var duration = +windowDuration || 0;
4229+
if (duration <= 0) { throw new RangeError('windowDuration cannot be less or equal zero.'); }
4230+
var source = this;
4231+
return new AnonymousObservable(function (observer) {
4232+
var lastOnNext = 0;
4233+
return source.subscribe(
4234+
function (x) {
4235+
var now = scheduler.now();
4236+
if (lastOnNext === 0 || now - lastOnNext >= duration) {
4237+
lastOnNext = now;
4238+
observer.onNext(x);
4239+
}
4240+
},
4241+
observer.onError.bind(observer),
4242+
observer.onCompleted.bind(observer)
4243+
);
4244+
});
4245+
};
4246+
42204247
var PausableObservable = (function (_super) {
42214248

42224249
inherits(PausableObservable, _super);

dist/rx.lite.compat.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/rx.lite.compat.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)