using System;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;

namespace Replikanto.Util
{
	public static class SOExtensions
	{
		public static async Task<T> WithTimeout<T>(this Task<T> task, int duration)
		{
			ConfiguredTaskAwaitable<Task>.ConfiguredTaskAwaiter configuredTaskAwaiter = Delegate696.smethod_0(new Task[]
			{
				task,
				Delegate25.smethod_0(duration, Delegate25.delegate25_0)
			}, Delegate696.delegate696_0).ConfigureAwait(false).GetAwaiter();
			if (!configuredTaskAwaiter.IsCompleted)
			{
				await configuredTaskAwaiter;
				ConfiguredTaskAwaitable<Task>.ConfiguredTaskAwaiter configuredTaskAwaiter2;
				configuredTaskAwaiter = configuredTaskAwaiter2;
				configuredTaskAwaiter2 = default(ConfiguredTaskAwaitable<Task>.ConfiguredTaskAwaiter);
			}
			T t;
			if (configuredTaskAwaiter.GetResult() is Task<T>)
			{
				t = task.Result;
			}
			else
			{
				t = default(T);
			}
			return t;
		}

		internal static void smethod_0()
		{
		}
	}
}
