Add pre-testing version of the webinterface

This commit is contained in:
Infi
2024-08-24 03:05:33 +02:00
parent 117d9fc45c
commit 5e93732183
27 changed files with 1498 additions and 129 deletions
+37
View File
@@ -0,0 +1,37 @@
namespace ChatTwo.Http;
public static class WebserverUtil
{
public static async Task<T> FrameworkWrapper<T>(Func<Task<T>> func)
{
return await Plugin.Framework.RunOnTick(func).ConfigureAwait(false);
}
public class DisposableWrapper : IDisposable {
private readonly Action Down;
private bool Disposed;
public DisposableWrapper(Action down) {
Down = down;
}
public void Dispose() {
if (Disposed) return;
Down();
Disposed = true;
GC.SuppressFinalize(this);
}
}
}
public static class AsyncUtils {
public static async Task<IDisposable> UseWaitAsync(this SemaphoreSlim semaphore, CancellationToken ct = default) {
await semaphore.WaitAsync(ct).ConfigureAwait(false);
return new WebserverUtil.DisposableWrapper(() => {
semaphore.Release();
});
}
}