public void CanInterceptNestedMessages() => AsyncContext.Run(async() => { var normalInterceptions = 0; var nestedInterceptions = 0; const int expected = 123; using (var loop = new MessageLoop <int>(() => expected, interceptor: (i, ctx) => { if (ctx.NestedMessage) { nestedInterceptions++; } else { normalInterceptions++; } return(ctx.Func(i)); })) { var x = await loop.GetAsync(async n => await loop.GetAsync(async n2 => await loop.GetAsync(n3 => n3))); Assert.AreEqual(expected, x); Assert.AreEqual(1, normalInterceptions); Assert.AreEqual(2, nestedInterceptions); } });
public void CanNestMessages() => AsyncContext.Run(async() => { const int expected = 123; using (var loop = new MessageLoop <int>(() => expected)) { var x = await loop.GetAsync(async n => await loop.GetAsync(async n2 => await loop.GetAsync(n3 => n3))); Assert.AreEqual(expected, x); } });
public void Stress() => AsyncContext.Run(async() => { const int workerCount = 10; const int iters = 100; using (var loop = new MessageLoop <Wrapper <int> >(() => new Wrapper <int>())) { var workers = System.Linq.Enumerable.Range(0, workerCount) .Select(i => { return(Task.Run(() => { for (int j = 0; j < iters; j++) { loop.DoAsync(w => w.Value++).Wait(); } })); }).ToArray(); Task.WaitAll(workers); var n = await loop.GetAsync(async x => { return(await Task.FromResult(x.Value)); }); Assert.AreEqual(workerCount * iters, n); } });
public void Stress() => AsyncContext.Run(async () => { const int workerCount = 10; const int iters = 100; using (var loop = new MessageLoop<Wrapper<int>>(() => new Wrapper<int>())) { var workers = System.Linq.Enumerable.Range(0, workerCount) .Select(i => { return Task.Run(() => { for (int j = 0; j < iters; j++) { loop.DoAsync(w => w.Value++).Wait(); } }); }).ToArray(); Task.WaitAll(workers); var n = await loop.GetAsync(async x => { return await Task.FromResult(x.Value); }); Assert.AreEqual(workerCount*iters, n); } });
public void CanGetAsync() => AsyncContext.Run(async() => { using (var loop = new MessageLoop <int>(() => 1)) { var n = await loop.GetAsync(x => x); Assert.AreEqual(1, n); } });
public void CanGetAsync() => AsyncContext.Run(async () => { using (var loop = new MessageLoop<int>(() => 1)) { var n = await loop.GetAsync(x => x); Assert.AreEqual(1, n); } });
async Task test() { using (var loop = new MessageLoop <string>(() => "")) await loop.GetAsync(state => Task.FromResult(DivZero())); }
public void TestGetAsyncException() => AsyncContext.Run(async() => { using (var loop = new MessageLoop <string>(() => "")) await loop.GetAsync(state => Task.FromResult(DivZero())); });
public void TestGetAsyncException() => AsyncContext.Run(async () => { using (var loop = new MessageLoop<string>(() => "")) await loop.GetAsync(state => Task.FromResult(DivZero())); });
public void CanInterceptNestedMessages() => AsyncContext.Run(async () => { var normalInterceptions = 0; var nestedInterceptions = 0; const int expected = 123; using (var loop = new MessageLoop<int>(() => expected, interceptor: (i, ctx) => { if (ctx.NestedMessage) nestedInterceptions++; else normalInterceptions++; return ctx.Func(i); })) { var x = await loop.GetAsync(async n => await loop.GetAsync(async n2 => await loop.GetAsync(n3 => n3))); Assert.AreEqual(expected, x); Assert.AreEqual(1, normalInterceptions); Assert.AreEqual(2, nestedInterceptions); } });
public void CanNestMessages() => AsyncContext.Run(async () => { const int expected = 123; using (var loop = new MessageLoop<int>(() => expected)) { var x = await loop.GetAsync(async n => await loop.GetAsync(async n2 => await loop.GetAsync(n3 => n3))); Assert.AreEqual(expected, x); } });