Exemple #1
0
        public AsyncCommandBuilder <T, C> CheckReentry()
        {
            var isExecuting = new VolatileFlag();
            var handler     = _command.Handler;

            _command.Handler = async p =>
            {
                if (isExecuting.Value)
                {
                    throw Exceptions.ReentrancyCheckFailed();
                }

                isExecuting.Value = true;

                try
                {
                    await handler(p);
                }
                finally
                {
                    isExecuting.Value = false;
                }
            };

            return(this);
        }
Exemple #2
0
        public AsyncCommandBuilder <T, C> IgnoreReentry()
        {
            var isExecuting = new VolatileFlag();
            var handler     = _command.Handler;

            _command.Handler = async p =>
            {
                if (isExecuting.Value)
                {
                    return;
                }

                isExecuting.Value = true;

                try
                {
                    await handler(p);
                }
                finally
                {
                    isExecuting.Value = false;
                }
            };

            return(this);
        }