using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AutoSellerNS
{
	public static class TaskExtensions
	{
		//public static async Task TimeoutAfter(this Task task, int millisecondsTimeout)
		//{
		//	if (task == await Task.WhenAny(task, Task.Delay(millisecondsTimeout)))
		//		await task;
		//	else
		//		throw new TimeoutException();
		//}

		public static async Task TimeoutAfter(Action action, int millisecondsTimeout)
		{
			Task task = new Task(action);
			if (task == await Task.WhenAny(task, Task.Delay(millisecondsTimeout)))
				await task;
			else
				throw new TimeoutException();
		}
	}
}
