1

New to RxSwift / Reactivex. Basically what I'm trying to do is to make a server call whenever something happens, but make sure it's not done more often than every 10 seconds. Less often if possible.

For instance, whenever an event ("needs update") is generated I'd like to call the server immediately if more than 10 seconds have passed since my last call. If less time has passed I'd like to make the call on the 10 second mark from the last one. It doesn't matter how many events have been generated within these 10 seconds.

I looked at the description of throttle but it appears to starve if events happen very quickly, which isn't desirable.

How can I achieve this?

Andreas
  • 2,665
  • 2
  • 29
  • 38
  • Could you elaborate on what you mean by "starve"? – solidcell May 24 '16 at 18:09
  • It means that events will not get delivered if they happen often enough. – Andreas May 24 '16 at 18:12
  • Where do you see that description? I haven't seen that in the docs nor experienced that myself. Could you link to it and paste the relevant text? – solidcell May 24 '16 at 18:32
  • Ah I see what you were talking about by "starve" now. I've added an answer. The answer might be helpful in the future, but I'll see if I can come up with something that helps you for now when I get a minute. – solidcell May 24 '16 at 20:57
  • Hi, thanks for the answer! I decided to solve it without Rx for the time being but I'd still be interested in how to do it the Rx way (preferably legibly). NSTimer isn't very beautiful. – Andreas May 24 '16 at 22:40

1 Answers1

1

There's a proposed new operator for RxSwiftExt that would give you something you're looking for, I think. However, it doesn't exist yet. You might want to keep an eye on it, though.

https://github.com/RxSwiftCommunity/RxSwiftExt/issues/10

solidcell
  • 7,639
  • 4
  • 40
  • 59