Skip to content

Instantly share code, notes, and snippets.

Created April 11, 2011 21:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/914453 to your computer and use it in GitHub Desktop.
Save anonymous/914453 to your computer and use it in GitHub Desktop.
/*
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