示例#1
0
        public static void SetDefaultFactory(PromiseBackend backend)
        {
            lock (_syncRoot)
            {
                if (_factory == null)
                {
                    _factory = new PromiseFactory(backend);
                    _backend = null;
                    if (backend == PromiseBackend.Default)
                    {
                        _backendType = PromiseFactory.DefaultBackend;
                    }
                    else
                    {
                        _backendType = backend;
                    }
                }
                else if (_backend != null)
                {
                    _factory.Dispose();
                    _factory = new PromiseFactory(backend);
                    _backend = null;

                    if (backend == PromiseBackend.Default)
                    {
                        _backendType = PromiseFactory.DefaultBackend;
                    }
                    else
                    {
                        _backendType = backend;
                    }
                }
                else if (_backendType != backend)
                {
                    _factory.Dispose();
                    _factory = new PromiseFactory(backend);

                    if (backend == PromiseBackend.Default)
                    {
                        _backendType = PromiseFactory.DefaultBackend;
                    }
                    else
                    {
                        _backendType = backend;
                    }
                }
            }
        }
示例#2
0
 public static void SetDefaultFactory(IBackend backend)
 {
     lock (_syncRoot)
     {
         if (_factory == null)
         {
             _factory = new PromiseFactory(backend);
             _backend = backend;
         }
         else if (!Object.Equals(_backend, backend))
         {
             _factory.Dispose();
             _factory = new PromiseFactory(backend);
             _backend = backend;
         }
     }
 }
示例#3
0
        public Promise(PromiseFactory factory, Action <Action, Action <Exception> > promise, PromisePriority priority)
        {
            _promise = factory.StartNew(() =>
            {
                Exception error = null;
                bool hasError   = false;

                promise(() =>
                {
                    error    = null;
                    hasError = false;
                }, x =>
                {
                    error    = x;
                    hasError = true;
                });

                if (hasError)
                {
                    throw error;
                }
            }, priority);
        }
示例#4
0
 public static IPromise JoinSerial <T>(this IEnumerable <IPromise <T> > items, PromiseFactory factory)
 {
     return(factory.JoinSerial(items));
 }
示例#5
0
 public static IPromise JoinParallel(this IEnumerable <IPromise> items, PromiseFactory factory)
 {
     return(factory.JoinParallel(items));
 }
示例#6
0
 public static IPromiseEnumerable <T> Promesify <T>(this IEnumerable <T> items, PromiseFactory factory)
 {
     return(new PromiseEnumerable <T>(factory, items));
 }
 public PromiseSynchronizationContext(PromiseFactory factory)
 {
     this._factory  = factory;
     this._last     = null;
     this._syncRoot = new object();
 }
示例#8
0
 public Promise(PromiseFactory factory, Action promise)
     : this(factory, promise, PromisePriority.Normal)
 {
 }
示例#9
0
 public Promise(PromiseFactory factory, Action promise, PromisePriority priority)
 {
     _promise = factory.StartNew(promise, priority);
 }
示例#10
0
 public Promise(PromiseFactory factory, Action <Action, Action <Exception> > promise)
     : this(factory, promise, PromisePriority.Normal)
 {
 }
示例#11
0
 public static PromiseSynchronizationContext CreateSynchronizationContext(PromiseFactory factory)
 {
     return(new PromiseSynchronizationContext(factory));
 }
示例#12
0
 public static IPromiseEnumerable <T> Enumerable <T>(PromiseFactory factory, IEnumerable <T> items)
 {
     return(new PromiseEnumerable <T>(factory, items));
 }