diff Implab/Parallels/AsyncPool.cs @ 14:e943453e5039 promises

Implemented interllocked queue fixed promise syncronization
author cin
date Wed, 06 Nov 2013 17:49:12 +0400
parents 6ec82bf68c8e
children 5a4b735ba669
line wrap: on
line diff
--- a/Implab/Parallels/AsyncPool.cs	Wed Nov 06 01:07:55 2013 +0400
+++ b/Implab/Parallels/AsyncPool.cs	Wed Nov 06 17:49:12 2013 +0400
@@ -16,13 +16,30 @@
 
 			ThreadPool.QueueUserWorkItem(param => {
 				try {
-					p.Resolve(func());
+					p.Resolve(func());
 				} catch(Exception e) {
 					p.Reject(e);
 				}
 			});
 
 			return p;
-		}
+		}
+
+        public static Promise<T> InvokeNewThread<T>(Func<T> func) {
+            var p = new Promise<T>();
+
+            var worker = new Thread(() => {
+                try {
+                    p.Resolve(func());
+                } catch (Exception e) {
+                    p.Reject(e);
+                }
+            });
+            worker.IsBackground = true;
+
+            worker.Start();
+
+            return p;
+        }
 	}
 }