locked
Throttle behaviour RRS feed

  • Question

  • My understanding of 'Throttle' is to regulate the flow of something to a maximum rate (in this case events per time interval).  Observable.Throttle instead filters out *all* events with a time interval of less than the provided value.  Should Throttle be renamed to something more appropriate, or should Throttle allow through at most one event every defined time interval?

    Wednesday, November 25, 2009 9:00 AM

Answers

  • Think of Intellisense: If you start coding and you want intellisense to show up only when you stop typing.
    Wednesday, November 25, 2009 6:10 PM

All replies

  • That threw me off at first too, until I realized I Sample() was what I needed for this, if you are looking to allow a maximum of 1 event through for every X seconds.

    It does make me curious though... Would it make sense for Sample() to be renamed Throttle(), and Throttle() be named something else?  What are some problems where the current behavior of Throttle() would be a useful tool?
    Wednesday, November 25, 2009 6:02 PM
  • Think of Intellisense: If you start coding and you want intellisense to show up only when you stop typing.
    Wednesday, November 25, 2009 6:10 PM
  • Ok, I can see why the current behaviour of Throttle is useful in that sense, but it's not what I call Throttle, and it's not Sample either.   Also Throttle wouldn't work in your example since it would eat all the key strokes that occurred too quickly, I think we'd use BufferWithTime or something like that.

    Sample: Take a sample every interval.  That's ok.
    Throttle (current behaviour): When events occurring too fast don't let through, else let through.
    Throttle (what I would expect): When events are occurring too fast then Sample, else let through.
    I suppose it's possible to construct my expected behaviour from Sample and Throttle.  Not sure how though.
    Wednesday, November 25, 2009 6:27 PM
  • I don't need the actual key strokes for intellisense.
    I can call something like textBox.Text to get the complete string - I only need to know when the user stops typing.

    Regards,
      Steffen
    Wednesday, November 25, 2009 6:30 PM
  • Ah, okay!  I was under the mistaken impression that Throttle would produce a value only if the time elapsed between the current and previous value was greater than the timespan passed in.

    Thanks... that definitely opens up good uses for Throttle!
    Wednesday, November 25, 2009 6:35 PM
  • Wes, I think it's just question of semantics.  I understand the current behaviour of the Throttle method as analagous to an electronic choke (i.e blocks high frequencies).  But I understand the word "throttle" to mean regulate the flow of something to a max rate (among other things).

    Observable.Throttle has choke behaviour (for me anyway).  What about rename Throttle to Choke since it completely blocks events with too high a frequency, and add a new method called Throttle that limits the event rate to the defined max rate.  And these are both different to Sample.

    e.g. currently,   var observable = GenerateFastEvents().Throttle(some slow value); 
    You won't see any events.

    But since choke and throttle can have similar meanings (as in strangle) maybe it's just my English language interpretation vs an American one.

    I guess it's not a big deal either way.
    Wednesday, December 2, 2009 8:16 AM
  • Ok, I can see why the current behaviour of Throttle is useful in that sense, but it's not what I call Throttle, and it's not Sample either. Also Throttle wouldn't work in your example since it would eat all the key strokes that occurred too quickly, I think we'd use BufferWithTime or something like that.

    Sample: Take a sample every interval. That's ok.
    Throttle (current behaviour): When events occurring too fast don't let through, else let through.
    Throttle (what I would expect): When events are occurring too fast then Sample, else let through.
    I suppose it's possible to construct my expected behaviour from Sample and Throttle. Not sure how though.

    It's very valuable, Thanks for your effort! I got more deep understanding about this part.
    Saturday, March 5, 2011 12:17 AM
  • I agree with this terminology suggestion: current throttle should be renamed choke, and throttle should be implemented to do something more like this to GenerateFastEvents: 

    GenerateFastEvents().Take(1).Concat(Observable.Empty().Delay(delayAmt)).Repeat()

    Friday, April 29, 2011 12:48 PM