mirror of
https://github.com/ElectronNET/Electron.NET.git
synced 2026-02-14 05:34:48 +00:00
Import SocketIO code
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
|
||||
namespace SocketIOClient.Extensions
|
||||
{
|
||||
internal static class CancellationTokenSourceExtensions
|
||||
{
|
||||
public static void TryDispose(this CancellationTokenSource cts)
|
||||
{
|
||||
cts?.Dispose();
|
||||
}
|
||||
|
||||
public static void TryCancel(this CancellationTokenSource cts)
|
||||
{
|
||||
cts?.Cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
12
ElectronNET.API/SocketIO/Extensions/DisposableExtensions.cs
Normal file
12
ElectronNET.API/SocketIO/Extensions/DisposableExtensions.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
|
||||
namespace SocketIOClient.Extensions
|
||||
{
|
||||
internal static class DisposableExtensions
|
||||
{
|
||||
public static void TryDispose(this IDisposable disposable)
|
||||
{
|
||||
disposable?.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
|
||||
namespace SocketIOClient.Extensions
|
||||
{
|
||||
internal static class EventHandlerExtensions
|
||||
{
|
||||
public static void TryInvoke<T>(this EventHandler<T> handler, object sender, T args)
|
||||
{
|
||||
handler?.Invoke(sender, args);
|
||||
}
|
||||
|
||||
public static void TryInvoke(this EventHandler handler, object sender, EventArgs args)
|
||||
{
|
||||
handler?.Invoke(sender, args);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
|
||||
namespace SocketIOClient.Extensions
|
||||
{
|
||||
internal static class SocketIOEventExtensions
|
||||
{
|
||||
public static void TryInvoke(this OnAnyHandler handler, string eventName, SocketIOResponse response)
|
||||
{
|
||||
try
|
||||
{
|
||||
handler(eventName, response);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// The exception is thrown by the user code, so it can be swallowed
|
||||
}
|
||||
}
|
||||
public static void TryInvoke(this Action<SocketIOResponse> handler, SocketIOResponse response)
|
||||
{
|
||||
try
|
||||
{
|
||||
handler(response);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// The exception is thrown by the user code, so it can be swallowed
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user