Esempio n. 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;
                    }
                }
            }
        }
Esempio n. 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;
         }
     }
 }
Esempio n. 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);
        }
Esempio n. 4
0
 public static IPromise JoinSerial <T>(this IEnumerable <IPromise <T> > items, PromiseFactory factory)
 {
     return(factory.JoinSerial(items));
 }
Esempio n. 5
0
 public static IPromise JoinParallel(this IEnumerable <IPromise> items, PromiseFactory factory)
 {
     return(factory.JoinParallel(items));
 }
Esempio n. 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();
 }
Esempio n. 8
0
 public Promise(PromiseFactory factory, Action promise)
     : this(factory, promise, PromisePriority.Normal)
 {
 }
Esempio n. 9
0
 public Promise(PromiseFactory factory, Action promise, PromisePriority priority)
 {
     _promise = factory.StartNew(promise, priority);
 }
Esempio n. 10
0
 public Promise(PromiseFactory factory, Action <Action, Action <Exception> > promise)
     : this(factory, promise, PromisePriority.Normal)
 {
 }
Esempio n. 11
0
 public static PromiseSynchronizationContext CreateSynchronizationContext(PromiseFactory factory)
 {
     return(new PromiseSynchronizationContext(factory));
 }
Esempio n. 12
0
 public static IPromiseEnumerable <T> Enumerable <T>(PromiseFactory factory, IEnumerable <T> items)
 {
     return(new PromiseEnumerable <T>(factory, items));
 }