using System;
using UnityEngine;
using System.Threading.Tasks;
using System.Collections;
using System.Collections.Generic;
namespace UnityAsync
{
	/// 
	/// Encapsulates a , allowing it to be yielded in an IEnumerator coroutine.
	/// 
	public class TaskYieldInstruction : CustomYieldInstruction
	{
		readonly Task task;
		public TaskYieldInstruction(Task task) => this.task = task;
		public override bool keepWaiting => !task.IsCompleted;
	}
	/// 
	/// Encapsulates a , allowing it to be yielded in an IEnumerator coroutine.
	/// 
	public class TaskYieldInstruction : IEnumerator
	{
		readonly Task task;
		public TaskYieldInstruction(Task task) => this.task = task;
		object IEnumerator.Current => Current;
		
		/// 
		/// Returns the encapsulated 's result if it has completed, otherwise the
		/// default TResult value.
		/// 
		public TResult Current => task.IsCompleted ? task.Result : default;
		public void Dispose() => task.Dispose();
		public bool MoveNext() => !task.IsCompleted;
		public void Reset() => throw new NotSupportedException();
	}
}