Mercurial > pub > ImplabNet
diff Implab.Fx/PromiseHelpers.cs @ 72:d67b95eddaf4 v2
promises refactoring
author | cin |
---|---|
date | Thu, 04 Sep 2014 18:47:12 +0400 |
parents | 381095ad0a69 |
children | c761fc982e1d |
line wrap: on
line diff
--- a/Implab.Fx/PromiseHelpers.cs Wed Sep 03 18:34:02 2014 +0400 +++ b/Implab.Fx/PromiseHelpers.cs Thu Sep 04 18:47:12 2014 +0400 @@ -1,7 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; using System.Windows.Forms; using System.Threading; @@ -32,22 +29,14 @@ if (ctl == null) throw new ArgumentNullException("ctl"); - var directed = new Promise<T>(); + var directed = new ControlBoundPromise<T>(ctl,that,true); that.Then( - res => - { - if (ctl.InvokeRequired) - ctl.Invoke(new Action<T>(directed.Resolve), res); - else - directed.Resolve(res); - }, + directed.Resolve, err => { - if (ctl.InvokeRequired) - ctl.Invoke(new Action<Exception>(directed.Reject), err); - else - directed.Reject(err); + directed.Reject(err); + return default(T); } ); @@ -86,7 +75,10 @@ that.Then( res => sync.Post(state => d.Resolve(res), null), - err => sync.Post(state => d.Reject(err), null) + err => { + sync.Post(state => d.Reject(err), null); + return default(T); + } ); return d;