|
| 1 | +// Licensed to the .NET Foundation under one or more agreements. |
| 2 | +// The .NET Foundation licenses this file to you under the MIT license. |
| 3 | + |
| 4 | +using System; |
| 5 | +using System.Net.Http.Headers; |
| 6 | +using System.Net.Http; |
| 7 | +using System.Threading.Tasks; |
| 8 | +using System.Threading; |
| 9 | +using System.Runtime.CompilerServices; |
| 10 | + |
| 11 | +public class Test |
| 12 | +{ |
| 13 | + public static int Main(string[] args) |
| 14 | + { |
| 15 | + var task = Work(); |
| 16 | + while (!task.IsCompleted) |
| 17 | + { |
| 18 | + WasiEventLoop.DispatchWasiEventLoop(); |
| 19 | + } |
| 20 | + var exception = task.Exception; |
| 21 | + if (exception is not null) |
| 22 | + { |
| 23 | + throw exception; |
| 24 | + } |
| 25 | + |
| 26 | + return 0; |
| 27 | + } |
| 28 | + |
| 29 | + public static async Task Work() |
| 30 | + { |
| 31 | + using HttpClient client = new(); |
| 32 | + client.Timeout = Timeout.InfiniteTimeSpan; |
| 33 | + client.DefaultRequestHeaders.Accept.Clear(); |
| 34 | + client.DefaultRequestHeaders.Accept.Add( |
| 35 | + new MediaTypeWithQualityHeaderValue("application/vnd.github.v3+json")); |
| 36 | + client.DefaultRequestHeaders.Add("User-Agent", ".NET Foundation Repository Reporter"); |
| 37 | + |
| 38 | + var query="https://api.github.com/orgs/dotnet/repos?per_page=1"; |
| 39 | + var json = await client.GetStringAsync(query); |
| 40 | + |
| 41 | + Console.WriteLine(); |
| 42 | + Console.WriteLine("GET "+query); |
| 43 | + Console.WriteLine(); |
| 44 | + Console.WriteLine(json); |
| 45 | + } |
| 46 | + |
| 47 | + private static class WasiEventLoop |
| 48 | + { |
| 49 | + internal static void DispatchWasiEventLoop() |
| 50 | + { |
| 51 | + CallDispatchWasiEventLoop((Thread)null!); |
| 52 | + |
| 53 | + [UnsafeAccessor(UnsafeAccessorKind.StaticMethod, Name = "DispatchWasiEventLoop")] |
| 54 | + static extern void CallDispatchWasiEventLoop(Thread t); |
| 55 | + } |
| 56 | + } |
| 57 | +} |
0 commit comments