Skip to content

Instantly share code, notes, and snippets.

@celsojr
Last active August 5, 2021 21:22
Show Gist options
  • Save celsojr/24620fd6ba3e47219804e1e72cfda52d to your computer and use it in GitHub Desktop.
Save celsojr/24620fd6ba3e47219804e1e72cfda52d to your computer and use it in GitHub Desktop.
Simple custom awaiter
using System;
using System.Threading.Tasks;
using System.Runtime.CompilerServices;
static class Program
{
static async Task Main()
{
Console.WriteLine("One second pls...");
await 1_000; // My custom type await :)
Console.WriteLine("Thank you for waiting!");
}
static TaskAwaiter GetAwaiter(this int miliseconds) =>
Task.Delay(miliseconds).GetAwaiter();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment