namespace Fort23.Core
{
    public class ManualAsyncTask
    {
        private CTask _cTask = null;

        public static ManualAsyncTask Create()
        {
            return new ManualAsyncTask();
        }

        public ManualAsyncTask()
        {
            _cTask = CTask.Create(false);
        }

        public async CTask Wait()
        {
            if (_cTask == null)
            {
                return;
            }

            await _cTask;
        }

        public void SetResult()
        {
            if (_cTask == null)
            {
                return;
            }

            _cTask.SetResult();
            _cTask = null;
        }
    }
}