using System; using System.Diagnostics; namespace Implab { class PromiseHandler { public static Action Create(Action handler, Deferred next) { Debug.Assert(handler != null); return (v) => { try { handler(v); next.Resolve(); } catch (Exception err) { next.Reject(err); } }; } public static Action Create(Func handler, Deferred next) { Debug.Assert(handler != null); return (v) => { try { next.Resolve(handler(v)); } catch (Exception err) { next.Reject(err); } }; } public static Action Create(Func handler, Deferred next) { Debug.Assert(handler != null); return (v) => { try { next.Resolve(handler(v)); } catch (Exception err) { next.Reject(err); } }; } public static Action Create(Func> handler, Deferred next) { Debug.Assert(handler != null); return (v) => { try { next.Resolve(handler(v)); } catch (Exception err) { next.Reject(err); } }; } public static Action Create(Action handler, Deferred next) { Debug.Assert(handler != null); return () => { try { handler(); next.Resolve(); } catch (Exception err) { next.Reject(err); } }; } public static Action Create(Func handler, Deferred next) { Debug.Assert(handler != null); return () => { try { next.Resolve(handler()); } catch (Exception err) { next.Reject(err); } }; } public static Action Create(Func handler, Deferred next) { Debug.Assert(handler != null); return () => { try { next.Resolve(handler()); } catch (Exception err) { next.Reject(err); } }; } public static Action Create(Func> handler, Deferred next) { Debug.Assert(handler != null); return () => { try { next.Resolve(handler()); } catch (Exception err) { next.Reject(err); } }; } } }