annotate 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
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.Diagnostics;
dc4942d09e74 improved tracing
cin
parents:
diff changeset
3 using Implab.Parallels;
dc4942d09e74 improved tracing
cin
parents:
diff changeset
4 using Implab;
103
cin
parents: 94
diff changeset
5 using System.Collections.Generic;
cin
parents: 94
diff changeset
6 using System.Collections.Concurrent;
136
e9e7940c7d98 shared locks + tests
cin
parents: 125
diff changeset
7 using System.Threading;
150
3258399cba83 JSONWriter improvements
cin
parents: 145
diff changeset
8 using Implab.JSON;
3258399cba83 JSONWriter improvements
cin
parents: 145
diff changeset
9 using System.IO;
151
ec91a6dfa5b3 Added support for 'await' operator to promises
cin
parents: 150
diff changeset
10 using System.Threading.Tasks;
93
dc4942d09e74 improved tracing
cin
parents:
diff changeset
11
dc4942d09e74 improved tracing
cin
parents:
diff changeset
12 namespace MonoPlay {
dc4942d09e74 improved tracing
cin
parents:
diff changeset
13 class MainClass {
145
706fccb85524 RC: cancellation support for promises + tests
cin
parents: 138
diff changeset
14
706fccb85524 RC: cancellation support for promises + tests
cin
parents: 138
diff changeset
15
93
dc4942d09e74 improved tracing
cin
parents:
diff changeset
16 public static void Main(string[] args) {
94
a43745f81f10 minor fixes
cin
parents: 93
diff changeset
17 if (args == null)
a43745f81f10 minor fixes
cin
parents: 93
diff changeset
18 throw new ArgumentNullException("args");
a43745f81f10 minor fixes
cin
parents: 93
diff changeset
19
103
cin
parents: 94
diff changeset
20 var t1 = Environment.TickCount;
93
dc4942d09e74 improved tracing
cin
parents:
diff changeset
21
151
ec91a6dfa5b3 Added support for 'await' operator to promises
cin
parents: 150
diff changeset
22 DoWork().GetAwaiter().GetResult();
150
3258399cba83 JSONWriter improvements
cin
parents: 145
diff changeset
23
103
cin
parents: 94
diff changeset
24 var t2 = Environment.TickCount;
125
f803565868a4 improved performance of promises
cin
parents: 124
diff changeset
25 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
26
dc4942d09e74 improved tracing
cin
parents:
diff changeset
27 }
136
e9e7940c7d98 shared locks + tests
cin
parents: 125
diff changeset
28
151
ec91a6dfa5b3 Added support for 'await' operator to promises
cin
parents: 150
diff changeset
29 static IPromise<int> DoItem(int x) {
ec91a6dfa5b3 Added support for 'await' operator to promises
cin
parents: 150
diff changeset
30 return Promise<int>.FromResult(x + 1);
ec91a6dfa5b3 Added support for 'await' operator to promises
cin
parents: 150
diff changeset
31 }
150
3258399cba83 JSONWriter improvements
cin
parents: 145
diff changeset
32
151
ec91a6dfa5b3 Added support for 'await' operator to promises
cin
parents: 150
diff changeset
33 static async Task<int> DoWork() {
ec91a6dfa5b3 Added support for 'await' operator to promises
cin
parents: 150
diff changeset
34 var c = 0;
ec91a6dfa5b3 Added support for 'await' operator to promises
cin
parents: 150
diff changeset
35 for (int i = 0; i < 10000000; i++)
ec91a6dfa5b3 Added support for 'await' operator to promises
cin
parents: 150
diff changeset
36 c = await DoItem(c);
ec91a6dfa5b3 Added support for 'await' operator to promises
cin
parents: 150
diff changeset
37 return c;
145
706fccb85524 RC: cancellation support for promises + tests
cin
parents: 138
diff changeset
38 }
136
e9e7940c7d98 shared locks + tests
cin
parents: 125
diff changeset
39
93
dc4942d09e74 improved tracing
cin
parents:
diff changeset
40 }
dc4942d09e74 improved tracing
cin
parents:
diff changeset
41 }