-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e9cc7a0
commit 4f5c7b2
Showing
3 changed files
with
71 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System; | ||
using System.Net.Http.Headers; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
using System.Threading; | ||
using System.Runtime.CompilerServices; | ||
|
||
public class Test | ||
{ | ||
public static int Main(string[] args) | ||
{ | ||
var task = Work(); | ||
while (!task.IsCompleted) | ||
{ | ||
WasiEventLoop.DispatchWasiEventLoop(); | ||
} | ||
var exception = task.Exception; | ||
if (exception is not null) | ||
{ | ||
throw exception; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
public static async Task Work() | ||
{ | ||
using HttpClient client = new(); | ||
client.Timeout = Timeout.InfiniteTimeSpan; | ||
client.DefaultRequestHeaders.Accept.Clear(); | ||
client.DefaultRequestHeaders.Accept.Add( | ||
new MediaTypeWithQualityHeaderValue("application/vnd.github.v3+json")); | ||
client.DefaultRequestHeaders.Add("User-Agent", ".NET Foundation Repository Reporter"); | ||
|
||
var query="https://api.github.com/orgs/dotnet/repos?per_page=1"; | ||
var json = await client.GetStringAsync(query); | ||
|
||
Console.WriteLine(); | ||
Console.WriteLine("GET "+query); | ||
Console.WriteLine(); | ||
Console.WriteLine(json); | ||
} | ||
|
||
private static class WasiEventLoop | ||
{ | ||
internal static void DispatchWasiEventLoop() | ||
{ | ||
CallDispatchWasiEventLoop((Thread)null!); | ||
|
||
[UnsafeAccessor(UnsafeAccessorKind.StaticMethod, Name = "DispatchWasiEventLoop")] | ||
static extern void CallDispatchWasiEventLoop(Thread t); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/mono/sample/wasi/http-p2/Wasip2.Http.Console.Sample.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>$(NetCoreAppCurrent)</TargetFramework> | ||
<!-- | ||
<WasmSingleFileBundle>true</WasmSingleFileBundle> | ||
<InvariantGlobalization>true</InvariantGlobalization> | ||
--> | ||
</PropertyGroup> | ||
|
||
<Target Name="RunSample" DependsOnTargets="RunSampleWithWasmtime" /> | ||
</Project> |