Mercurial > pub > ImplabNet
diff MonoPlay/Program.cs @ 151:ec91a6dfa5b3 v2
Added support for 'await' operator to promises
author | cin |
---|---|
date | Thu, 04 Feb 2016 02:43:05 +0300 |
parents | 3258399cba83 |
children | 97fbbf816844 |
line wrap: on
line diff
--- a/MonoPlay/Program.cs Sat Dec 12 22:12:44 2015 +0300 +++ b/MonoPlay/Program.cs Thu Feb 04 02:43:05 2016 +0300 @@ -7,6 +7,7 @@ using System.Threading; using Implab.JSON; using System.IO; +using System.Threading.Tasks; namespace MonoPlay { class MainClass { @@ -18,26 +19,22 @@ var t1 = Environment.TickCount; - for(int i =0; i < 1000000; i++) - using (var tw = new StringWriter()) { - var jw = new JSONWriter(tw); - - jw.WriteValue("\r\nhere\tvalue\u0002\u0003"); - - //Console.WriteLine(tw); - } - - + DoWork().GetAwaiter().GetResult(); var t2 = Environment.TickCount; Console.WriteLine("done: {0} ms, {1:.00} Mb, {2} GC", t2 - t1, GC.GetTotalMemory(false) / (1024*1024), GC.CollectionCount(0) ); } - static void DoTest() { + static IPromise<int> DoItem(int x) { + return Promise<int>.FromResult(x + 1); + } - - + static async Task<int> DoWork() { + var c = 0; + for (int i = 0; i < 10000000; i++) + c = await DoItem(c); + return c; } }