annotate MonoPlay/Program.cs @ 159:5558e43c79bb v2

minor fix
author cin
date Thu, 18 Feb 2016 16:06:14 +0300
parents 97fbbf816844
children 4f82e0f161c3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
93
dc4942d09e74 improved tracing
cin
parents:
diff changeset
1 using System;
dc4942d09e74 improved tracing
cin
parents:
diff changeset
2 using Implab;
151
ec91a6dfa5b3 Added support for 'await' operator to promises
cin
parents: 150
diff changeset
3 using System.Threading.Tasks;
93
dc4942d09e74 improved tracing
cin
parents:
diff changeset
4
dc4942d09e74 improved tracing
cin
parents:
diff changeset
5 namespace MonoPlay {
dc4942d09e74 improved tracing
cin
parents:
diff changeset
6 class MainClass {
145
706fccb85524 RC: cancellation support for promises + tests
cin
parents: 138
diff changeset
7
706fccb85524 RC: cancellation support for promises + tests
cin
parents: 138
diff changeset
8
93
dc4942d09e74 improved tracing
cin
parents:
diff changeset
9 public static void Main(string[] args) {
94
a43745f81f10 minor fixes
cin
parents: 93
diff changeset
10 if (args == null)
a43745f81f10 minor fixes
cin
parents: 93
diff changeset
11 throw new ArgumentNullException("args");
a43745f81f10 minor fixes
cin
parents: 93
diff changeset
12
103
cin
parents: 94
diff changeset
13 var t1 = Environment.TickCount;
93
dc4942d09e74 improved tracing
cin
parents:
diff changeset
14
151
ec91a6dfa5b3 Added support for 'await' operator to promises
cin
parents: 150
diff changeset
15 DoWork().GetAwaiter().GetResult();
150
3258399cba83 JSONWriter improvements
cin
parents: 145
diff changeset
16
103
cin
parents: 94
diff changeset
17 var t2 = Environment.TickCount;
125
f803565868a4 improved performance of promises
cin
parents: 124
diff changeset
18 Console.WriteLine("done: {0} ms, {1:.00} Mb, {2} GC", t2 - t1, GC.GetTotalMemory(false) / (1024*1024), GC.CollectionCount(0) );
93
dc4942d09e74 improved tracing
cin
parents:
diff changeset
19
dc4942d09e74 improved tracing
cin
parents:
diff changeset
20 }
136
e9e7940c7d98 shared locks + tests
cin
parents: 125
diff changeset
21
151
ec91a6dfa5b3 Added support for 'await' operator to promises
cin
parents: 150
diff changeset
22 static IPromise<int> DoItem(int x) {
156
97fbbf816844 Promises: SignalXXX methods merged into SignalHandler method.
cin
parents: 151
diff changeset
23 //return Promise<int>.FromResult(x + 1);
97fbbf816844 Promises: SignalXXX methods merged into SignalHandler method.
cin
parents: 151
diff changeset
24 var p = new Promise<int>();
97fbbf816844 Promises: SignalXXX methods merged into SignalHandler method.
cin
parents: 151
diff changeset
25 p.Resolve(x+1);
97fbbf816844 Promises: SignalXXX methods merged into SignalHandler method.
cin
parents: 151
diff changeset
26 return p;
151
ec91a6dfa5b3 Added support for 'await' operator to promises
cin
parents: 150
diff changeset
27 }
150
3258399cba83 JSONWriter improvements
cin
parents: 145
diff changeset
28
151
ec91a6dfa5b3 Added support for 'await' operator to promises
cin
parents: 150
diff changeset
29 static async Task<int> DoWork() {
ec91a6dfa5b3 Added support for 'await' operator to promises
cin
parents: 150
diff changeset
30 var c = 0;
ec91a6dfa5b3 Added support for 'await' operator to promises
cin
parents: 150
diff changeset
31 for (int i = 0; i < 10000000; i++)
ec91a6dfa5b3 Added support for 'await' operator to promises
cin
parents: 150
diff changeset
32 c = await DoItem(c);
ec91a6dfa5b3 Added support for 'await' operator to promises
cin
parents: 150
diff changeset
33 return c;
145
706fccb85524 RC: cancellation support for promises + tests
cin
parents: 138
diff changeset
34 }
136
e9e7940c7d98 shared locks + tests
cin
parents: 125
diff changeset
35
93
dc4942d09e74 improved tracing
cin
parents:
diff changeset
36 }
dc4942d09e74 improved tracing
cin
parents:
diff changeset
37 }