public DoingJobParam(Func <TIn, TOut> func, TIn input, ResultSet <TOut> resultSet,
                      AutoResetEventSetter eventSetter, CancellationToken token)
 {
     EventSetter = eventSetter;
     Token       = token;
     Func        = func;
     Input       = input;
     ResultSet   = resultSet;
 }
Beispiel #2
0
        public TResult Provide(TInput inputParam)
        {
            var tokenSource = new CancellationTokenSource();
            var token       = tokenSource.Token;
            var eventSetter = new AutoResetEventSetter(_autoResetEvent);
            var resultSet   = new ResultSet <TResult>();

            foreach (var function in _functions)
            {
                Task.Factory.StartNew(DoJobAction,
                                      new DoingJobParam <TInput, TResult>(function, inputParam, resultSet, eventSetter, token), token,
                                      TaskCreationOptions.LongRunning, TaskScheduler.Default);
            }

            _autoResetEvent.WaitOne();
            tokenSource.Cancel(false);
            return(resultSet.Result);
        }