Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does C# have a built in way to throttle a function's number of calls? [closed]

Tags:

c#

I've got a single function that executes an HTTP request. I use this function all throughout a simple program I've written. I need to throttle these HTTP requests though so that I do not exceed rate limits. In the JavaScript world, there's a really handy third party library that provides a throttle function that returns a new function that calls your own function but will queue up the calls so that they only occur X times per minute or whatever.

Is there a built in C# way of doing this, or a handy pattern or nuget pkg for this?

like image 552
Ryan Avatar asked Jun 13 '16 16:06

Ryan


People also ask

Does C have do-while?

The C do while statement creates a structured loop that executes as long as a specified condition is true at the end of each pass through the loop.

What is the do in C?

The do-while statement lets you repeat a statement or compound statement until a specified expression becomes false.

What does |= mean in C?

The ' |= ' symbol is the bitwise OR assignment operator.


1 Answers

If you use Reactive Extensions, you can take advantage of the Observable.Throttle() method: https://msdn.microsoft.com/en-us/library/hh229400(v=vs.103).aspx

The Reactive Extensions page can be found at http://reactivex.io/

like image 52
Rob Lyndon Avatar answered Sep 17 '22 15:09

Rob Lyndon