Flatwhite.Hot.RaisingPhoenix.Reborn C# (CSharp) Method

Reborn() public method

true if the phoenix is executing rebornAction. This is to avoid many call on method Reborn many time
public Reborn ( Func rebornAction ) : IPhoenixState
rebornAction Func
return IPhoenixState
        public IPhoenixState Reborn(Func<Task<IPhoenixState>> rebornAction)
        {
            if (_newPhoenixState != null)
            {
                return _newPhoenixState;
            }

            if (!_startable)
            {
                return this;
            }

            _startable = false;
            Func<Task<IPhoenixState>> wrapper = async () =>
            {
                try
                {
                    var t = rebornAction();
                    _newPhoenixState = await t;
                }
                catch
                {
                    _startable = true;
                }

                return _newPhoenixState;
            };
            Global.BackgroundTaskManager.Run(wrapper);
            
            return this;
        }

Usage Example

        public void Reborn_should_not_call_reborn_on_result_if_task_completed_and_just_return_the_returned_phoenixState()
        {
            IPhoenixState reborn = Substitute.For<IPhoenixState>();
            Func<Task<IPhoenixState>> action = () => Task.FromResult(reborn);
            var state = new RaisingPhoenix();
            IPhoenixState rebornState;
            do
            {
                rebornState = state.Reborn(action);
            } while (object.ReferenceEquals(rebornState, state));

            reborn.Received(0).Reborn(Arg.Any<Func<Task<IPhoenixState>>>());
        }
All Usage Examples Of Flatwhite.Hot.RaisingPhoenix::Reborn
RaisingPhoenix