ReactiveX / rxjs

A reactive programming library for JavaScript
https://rxjs.dev
Apache License 2.0
30.7k stars 3k forks source link

Missing polymorphic behavior (delayWhen) in RxJS 5 #1202

Closed iemejia closed 8 years ago

iemejia commented 8 years ago

I was trying to create a randomly delayed Observable like this:

"use strict";

var Rx = require('rx');
// var Rx = require('rxjs/Rx');

var source = Rx.Observable.range(0, 100)
    .take(20)
    .delay(x => Rx.Observable.timer(Math.floor(Math.random() * 10000)));

var delayedSubscriber = source.subscribe(
  function (x) { console.log('onNext: %s', x); },
  function (e) { console.log('onError: %s', e); },
  function () { console.log('onCompleted'); }
);

I am not sure if this is the correct way to do what I intend, but I noticed a different behavior when I tested in RxJS 5 and nothing happened. Is it an issue, or did something change in the semantics that I didn't read ?

Thanks.

kwonoj commented 8 years ago

Somewhat yes. As migration guide shows, RxJS5 have separated operator for RxJS4's polymorphic behaved operators. (i.e, debouce & debounceTime). delay also had polymorphic signatures of accepting dateTime and subscriptionDelay with durationSelector, and latter is not added in current codebase yet, so above code snippet does nothing for you.

I remember there was discussion about this at https://github.com/ReactiveX/RxJS/issues/549 and agreed to have delayWhen which has not landed yet.

Does this answer your question? If you'd like to have delayWhen, I can suggest change this issue's subject to request of delayWhen to track its implementation.

iemejia commented 8 years ago

Thanks for answering. I read the migration guide, but as delay was not mentioned in the 'Operator Splits' section I didn't remember it was a polymorphic operator too. I will change the subject and I hope the delayWhen operator gets migrated and added to the guide.

kwonoj commented 8 years ago

delay was not mentioned

Yes, it's missing in guide, I just wanted to pick other examples in guide for separated operators.

kwonoj commented 8 years ago

I'll try to spend some time to make this operator lands in codebase.

kwonoj commented 8 years ago

Closing via https://github.com/ReactiveX/RxJS/pull/1245.

lock[bot] commented 6 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.