# HG changeset patch # User cin # Date 2013-08-27 04:28:42 # Node ID 6fb3b01ee971a8704df6f0e7a46ed584c2eda4b7 # Parent 279591fb4df3bcfb6ef677edcb43c43a114d5788 Added utility class for safe disposing methods. Added event fireing while promise is cancelled (needs some more work) diff --git a/Implab/Promise.cs b/Implab/Promise.cs --- a/Implab/Promise.cs +++ b/Implab/Promise.cs @@ -127,7 +127,12 @@ namespace Implab { 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; diff --git a/Implab/Safe.cs b/Implab/Safe.cs new file mode 100644 --- /dev/null +++ b/Implab/Safe.cs @@ -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(ref T obj) where T : IDisposable + { + if (obj != null) + { + obj.Dispose(); + obj = default(T); + } + } + } +}