The takeLastWithTime
operator takes a temporal duration rather than a quantity of items. It
emits only those items that are emitted during that final duration of the source Observable’s
lifespan. You set this duration by passing in a number of milliseconds as a parameter to
takeLastWithTime
.
Note that the mechanism by which this is implemented will delay the emission of any item from the source
Observable until that Observable completes.
takeLastWithTime
by default operates the timer on the timeout
Scheduler and emits items on the currentThread
Scheduler,
but you may also pass in Schedulers of your choosing to override these, as an optional second and third
parameters, respectively.
Sample Code
var source = Rx.Observable.timer(0, 1000)
.take(10)
.takeLastWithTime(5000);
var subscription = source.subscribe(
function (x) { console.log('Next: ' + x); },
function (err) { console.log('Error: ' + err); },
function () { console.log('Completed'); });
Next: 5
Next: 6
Next: 7
Next: 8
Next: 9
Completed
takeLastWithTime
is found in each of the following distributions:
rx.all.js
rx.all.compat.js
rx.time.js
(requires rx.js
or rx.compat.js
)
rx.lite.js
rx.lite.compat.js