Beispiel #1
0
        async Task PumpQueue()
        {
            var dispatchedList = new List <Task>();

            while (true)
            {
                var job = await _queue.Read();

                dispatchedList.Add(Dispatch(job, _queue.Configuration));
                if (dispatchedList.Count == _throttle)
                {
                    dispatchedList.Remove(await Task.WhenAny(dispatchedList));
                }
            }
// ReSharper disable once FunctionNeverReturns
        }
Beispiel #2
0
            public MaxWorkers()
            {
                var readTask = Task.FromResult((Dependable.Job)_world.NewJob);                
                
                _queue = Substitute.For<IJobQueue>();
                _queue.Configuration.Returns(new ActivityConfiguration().WithMaxWorkers(1));
                
                _queue.Read().Returns(c =>
                {
                    if (_readInvocations.Count != 0)
                        _readInvocations.Dequeue().SetResult(new object());
                    return readTask;
                });

                _world.Dispatcher.Dispatch(null, null).ReturnsForAnyArgs(c =>
                {
                    _dispatchInvocations.Dequeue().SetResult(new object());
                    return _dispatchResults.Dequeue().Task;
                });
            }
Beispiel #3
0
            public MaxWorkers()
            {
                var readTask = Task.FromResult((Dependable.Job)_world.NewJob);

                _queue = Substitute.For <IJobQueue>();
                _queue.Configuration.Returns(new ActivityConfiguration().WithMaxWorkers(1));

                _queue.Read().Returns(c =>
                {
                    if (_readInvocations.Count != 0)
                    {
                        _readInvocations.Dequeue().SetResult(new object());
                    }
                    return(readTask);
                });

                _world.Dispatcher.Dispatch(null, null).ReturnsForAnyArgs(c =>
                {
                    _dispatchInvocations.Dequeue().SetResult(new object());
                    return(_dispatchResults.Dequeue().Task);
                });
            }