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