Exemplo n.º 1
0
        public PipeLine(
            DataflowOptions dataflowOptions,
            int maxDegreeOfParallelism,
            HttpClient client)
            : base(dataflowOptions)
        {
            _client          = client;
            _dataflowOptions = dataflowOptions;
            _options         = dataflowOptions.ToExecutionBlockOption(true);
            _options.MaxDegreeOfParallelism    = maxDegreeOfParallelism;
            _options.BoundedCapacity           = 10000;
            _options.MaxMessagesPerTask        = 100;
            _options.SingleProducerConstrained = true;

            _requestBlock = new TransformBlock <string, HttpResponseMessage>(x =>
            {
                Interlocked.Increment(ref _totalOut);

                Console.WriteLine("lines " + _totalOut);

                var response = _client.GetAsync("http://localhost:3000/endpoint/info").Result;

                return(default(HttpResponseMessage));
            }, _options);

            _flowBlock = new ActionBlock <HttpResponseMessage>(x =>
            {
            }, _options);

            _request = _requestBlock.ToDataflow(_dataflowOptions, "Request");
            _flow    = _flowBlock.ToDataflow(_dataflowOptions, "Flow");

            _request.LinkTo(_flow);
        }
Exemplo n.º 2
0
            protected override Dataflow <Tracked <ICommand> > CreateChildFlow(string target)
            {
                var block = new ActionBlock <Tracked <ICommand> >(
                    async c =>
                {
                    await _handler(c.Value);
                    c.Complete();
                }, _options.ToDataflowBlockOptions());

                return(block.ToDataflow(_options));
            }