Exemple #1
0
        protected override IStream <TOut> CreateOutputStream(ToSubProcessesArgs <TIn, TOut> args)
        {
            // Semaphore semaphore = args.NoParallelisation ? new Semaphore(1, 1) : new Semaphore(10, 10);
            Synchronizer synchronizer = new Synchronizer(args.NoParallelisation);

            if (this.ExecutionContext is GetDefinitionExecutionContext)
            {
                var inputStream = new SingleStream <TIn>(new SubNodeWrapper(this), PushObservable.FromSingle(default(TIn), args.Stream.Observable.CancellationToken));
                foreach (var subProcess in args.SubProcesses)
                {
                    var outputStream = subProcess(inputStream);
                    this.ExecutionContext.AddNode(this, outputStream.Observable);
                }
            }

            var outputObservable = args.Stream.Observable
                                   .FlatMap((i, ct) => PushObservable.FromEnumerable(args.SubProcesses.Select(sp => new
            {
                config  = i,
                subProc = sp
            }), ct))
                                   .FlatMap((i, ct) =>
            {
                EventWaitHandle waitHandle = new EventWaitHandle(false, EventResetMode.ManualReset);
                var inputStream            = new SingleStream <TIn>(new SubNodeWrapper(this), PushObservable.FromSingle(i.config, waitHandle, ct));
                var outputStream           = i.subProc(inputStream);
                IDisposable awaiter        = null;
                outputStream.Observable.Subscribe(j => { }, () => awaiter?.Dispose());
                return(new DeferredWrapperPushObservable <TOut>(outputStream.Observable, () =>
                {
                    awaiter = synchronizer.WaitBeforeProcess();
                    waitHandle.Set();
                }, null, ct));
            });

            return(base.CreateUnsortedStream(outputObservable));
        }
Exemple #2
0
 public ToSubProcessesStreamNode(string name, ToSubProcessesArgs <TIn, TOut> args) : base(name, args)
 {
 }