changeset 1:6fb3b01ee971

Added utility class for safe disposing methods. Added event fireing while promise is cancelled (needs some more work)
author cin
date Tue, 27 Aug 2013 08:28:42 +0400
parents 279591fb4df3
children aa367305156b
files Implab/Promise.cs Implab/Safe.cs
diffstat 2 files changed, 25 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/Implab/Promise.cs	Fri Aug 23 04:38:46 2013 +0400
+++ b/Implab/Promise.cs	Tue Aug 27 08:28:42 2013 +0400
@@ -127,7 +127,12 @@
 		public bool Cancel() {
 			lock(this) {
 				if (m_state == State.Unresolved && m_cancellable) {
-					m_state = State.Cancelled;
+					m_state = State.Cancelled;
+                    EventHandler temp = Cancelled;
+                    
+                    if (temp != null)
+                        temp(this,new EventArgs());
+                    
 					return true;
 				} else
 					return false;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Implab/Safe.cs	Tue Aug 27 08:28:42 2013 +0400
@@ -0,0 +1,19 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Implab
+{
+    public static class Safe
+    {
+        public static void Dispose<T>(ref T obj) where T : IDisposable
+        {
+            if (obj != null)
+            {
+                obj.Dispose();
+                obj = default(T);
+            }
+        }
+    }
+}