Skip to content

Instantly share code, notes, and snippets.

@ihordyrman
Created February 13, 2022 07:27
Show Gist options
  • Save ihordyrman/0b897e9e49a946ec62a94b4dcc0dcd2b to your computer and use it in GitHub Desktop.
Save ihordyrman/0b897e9e49a946ec62a94b4dcc0dcd2b to your computer and use it in GitHub Desktop.
Int awaiting
using System;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
public class Program
{
public static async Task Main()
{
Console.WriteLine(await 1);
}
}
public static class IntTaskExtensions
{
public static IntAwaiter GetAwaiter(this int number) => new IntAwaiter(number);
public class IntAwaiter : INotifyCompletion
{
private int result;
public IntAwaiter(int number)
{
result = number + 1;
}
public bool IsCompleted => true;
public void OnCompleted(Action continuation) { }
public int GetResult() { return result; }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment