コード例 #1
0
 public virtual IFuture <T> Submit(IRunnableFuture <T> runnableFuture)
 {
     if (runnableFuture == null)
     {
         throw new ArgumentNullException("runnableFuture");
     }
     return(DoSubmit(runnableFuture));
 }
コード例 #2
0
            internal QueueingFuture(ExecutorCompletionService <T> enclosingInstance, IRunnableFuture <T> task)
                : base(task, null)
            {
                _enclosingInstance = enclosingInstance;
                _task = task;
                var contextCopyingTask = task as IContextCopyingTask;

                if (contextCopyingTask != null && contextCopyingTask.ContextCarrier != null)
                {
                    // The task is already copying the context, so we don't do it again.
                    ((IContextCopyingTask)this).ContextCarrier = NoContextCarrier.Instance;
                }
            }
コード例 #3
0
        private List <IFuture <T> > DoInvokeAll <T>(IEnumerable tasks, int count, Converter <object, IRunnableFuture <T> > converter)
        {
            if (tasks == null)
            {
                throw new ArgumentNullException("tasks");
            }
            List <IFuture <T> > futures = count > 0 ?  new List <IFuture <T> >(count) : new List <IFuture <T> >();
            bool done = false;

            try
            {
                foreach (object task in tasks)
                {
                    IRunnableFuture <T> runnableFuture = converter(task);
                    futures.Add(runnableFuture);
                    Execute(runnableFuture);
                }
                foreach (IFuture <T> future in futures)
                {
                    if (!future.IsDone)
                    {
                        try
                        {
                            future.GetResult();
                        }
                        catch (CancellationException)
                        {
                        }
                        catch (ExecutionException)
                        {
                        }
                    }
                }
                done = true;
                return(futures);
            }
            finally
            {
                if (!done)
                {
                    foreach (IFuture <T> future in futures)
                    {
                        future.Cancel(true);
                    }
                }
            }
        }
コード例 #4
0
 internal IFuture <T> DoSubmit(IRunnableFuture <T> runnableFuture)
 {
     _executor.Execute(new QueueingFuture(this, runnableFuture));
     return(runnableFuture);
 }
コード例 #5
0
 private IFuture <T> Submit <T>(IRunnableFuture <T> runnableFuture)
 {
     Execute(runnableFuture);
     return(runnableFuture);
 }
コード例 #6
0
 internal QueueingFuture(ExecutorCompletionService <T> enclosingInstance, IRunnableFuture <T> task)
     : base(task, null)
 {
     _enclosingInstance = enclosingInstance;
     _task = task;
 }