Designing a custom scheduler

Usually, all the needed schedulers already exists. Although, sometimes, it may happen that we may need a custom scheduler because we may need to choose how to schedule our jobs by ourselves. In the next example, we will see how to create a scheduler to throttle message flowing based on the CPU time. The CpuThrottlingScheduler method will verify each message flowing if the CPU time is at the desired level. Then, eventually, the observer's implementation will receive the message in the context thread of the ThreadPool thread to achieve multithreading if multiple subscribers exist.

Here is the scheduler code:

 /// <summary> /// Enqueues unit of works only if the current CPU time is lower than the /// specified limit. /// ...

Get Reactive Programming for .NET Developers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.