Helios.Ops.Executors.TryCatchExecutor.Execute C# (CSharp) Method

Execute() public method

public Execute ( System.Action op ) : void
op System.Action
return void
        public override void Execute(Action op)
        {
            try
            {
                if (!AcceptingJobs) return;
                op();
            }
            catch (Exception ex)
            {
                _exceptionCallback(ex);
            }
        }

Same methods

TryCatchExecutor::Execute ( IList ops, Action remainingOps ) : void

Usage Example

Ejemplo n.º 1
0
        public void Should_pipe_remaining_operations_when_exception_thrown()
        {
            //arrange
            var handledException = false;
            var remainingJobsCalled = true;
            var remainingJobsCount = 0;
            Action<Exception> exCallback = exception => { handledException = true; };
            Action exOperation = () => { throw new Exception("Plain old exception"); };
            Executor = new TryCatchExecutor(exCallback);

            var wasCalled = 3.Of(false).ToList();
            var callbacks = new Action[wasCalled.Count];

            for (var i = 0; i < wasCalled.Count; i++)
            {
                var i1 = i;
                callbacks[i] = new Action(() => { wasCalled[i1] = true; });
            }
            callbacks[1] = exOperation;

            //act
            Executor.Execute(callbacks, actions =>
            {
                remainingJobsCalled = true;
                remainingJobsCount = actions.Count();
            });

            //assert
            Assert.IsFalse(wasCalled.All(x => x));
            Assert.IsTrue(handledException);
            Assert.IsTrue(remainingJobsCalled);
            Assert.AreEqual(1, remainingJobsCount);
        }
All Usage Examples Of Helios.Ops.Executors.TryCatchExecutor::Execute