Monday, March 11, 2019

What approach would you take to throttle async events?

Consider the following stubbed class.

``` public class EventThrottler { private TimeSpan _delay = TimeSpan.FromSeconds(5);

public void TriggerEvent() { // Begin a timer to release callers of "AwaitEvent". // If a timer has already begun, push it back // for the length of 5 seconds. // This method should not block at all. } public Task AwaitEvent(CancellationToken token) { // Multiple people can await. // Callers will be released exactly // 5 seconds after the last call // to "TriggerEvent". // The awaits of this method will do // whatever the "event" is. return Task.CompletedTask; } 

} ```

What types would you use here? How would you implement this?

What approach would you take to throttle async events? Click here
  • Blogger Comment
  • Facebook Comment

0 comments:

Post a Comment

The webdev Team