-
-
Save joshrobb/915378 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Subject / EventLoopScheduler / CompositeDisposable are all from the Reactive Library for .Net 3.5. | |
Most of these classes are baked into .NET 4 AFAIK | |
*/ | |
// Event loop and queue setup done in constructor | |
_sendQueue = new Subject<Action>(); | |
var scheduler = new EventLoopScheduler( "EmailSender" ); | |
var queueSubscription = _sendQueue.ObserveOn( scheduler ).Subscribe( action => action() ); | |
_queueCleanup = new CompositeDisposable( queueSubscription, scheduler ); | |
// Queueing a new task - just dumps an action on the queue | |
var sendDetails = new SendDetails {SurveyId = survey.Id, SenderId = sender.Id}; | |
_sendQueue.OnNext( ()=> SendInvites( sendDetails ) ); | |
// Cleanup the queue - encapsulating type implements IDisposable | |
_queueCleanup.Dispose(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment