Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.29 KB | None | 0 0
  1. using System;
  2. using System.Diagnostics;
  3. using System.Runtime.CompilerServices;
  4. using System.Threading.Tasks;
  5.  
  6. namespace ConsoleApp1
  7. {
  8.     class Program
  9.     {
  10.         static async Task Main(string[] args)
  11.         {
  12.             var a = await 10;
  13.             Console.WriteLine(a);
  14.             Debugger.Break();
  15.         }
  16.     }
  17.  
  18.     static class WeirdIntExtension
  19.     {
  20.         public static IntAwaiter GetAwaiter(this int i) => new IntAwaiter();
  21.  
  22.         internal class IntAwaiter : INotifyCompletion
  23.         {
  24.             private readonly Task _timeoutTask;
  25.             public IntAwaiter()
  26.             {
  27.                 _timeoutTask = Task.Delay(TimeSpan.FromSeconds(15));
  28.                 Debugger.Break();
  29.             }
  30.  
  31.             public bool IsCompleted
  32.             {
  33.                 get
  34.                 {
  35.                     Console.WriteLine($"Task status: {_timeoutTask.Status}");
  36.                     return _timeoutTask.IsCompleted;
  37.                 }
  38.             }
  39.  
  40.             public void OnCompleted(Action continuation)
  41.             {
  42.                 Console.WriteLine("Before continuation");
  43.                 continuation();
  44.                 Console.WriteLine("After continuation");
  45.             }
  46.  
  47.             public double GetResult() => 5.5;
  48.         }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement