Skip to content

Instantly share code, notes, and snippets.

@abolibibelot
Created May 2, 2011 15:43
Show Gist options
  • Save abolibibelot/951801 to your computer and use it in GitHub Desktop.
Save abolibibelot/951801 to your computer and use it in GitHub Desktop.
somedispatch
[TestMethod]
public void RecordDispatchTest()
{
var ads = new FlushingQueue<RecordModel> {Threshold = 2000};
var noAds = new FlushingQueue<RecordModel> {Threshold = 2000};
var rootDir = Directory.GetCurrentDirectory();
ads.FilenameProvider = () => rootDir + "/ads_" + Guid.NewGuid() + "_ads.txt";
noAds.FilenameProvider = () => rootDir + "/no_" + Guid.NewGuid() + "_noads.txt";
var rnd = new Random();
var records = (from i in Enumerable.Range(1, 100000)
let rand = rnd.NextDouble()
select new {Record = new RecordModel {Feature = rand < 0.25 ? "toto" : "Ads"}, Rand = rand })
//.Do(z => Console.WriteLine(z.Rand))
.Select(z => z.Record);
Action<RecordModel> adFilter = r => { if (r.Feature == "Ads") ads.Enqueue(r); };
Action<RecordModel> noAdFilter = r => { if (r.Feature != "Ads") noAds.Enqueue(r); };
records.DispatchTo(new[] {adFilter, noAdFilter});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment