Add flag to check if the socket is connected

This commit is contained in:
theolivenbaum
2021-09-02 18:20:11 +02:00
parent bb8965fa91
commit 47f4516ae2
2 changed files with 7 additions and 4 deletions

View File

@@ -95,6 +95,8 @@ namespace ElectronNET.API
private static Task _waitForConnection => _waitForBeingConnected.Task;
public static bool IsConnected => _waitForConnection is Task task && task.IsCompletedSuccessfully;
public static void Emit(string eventString, params object[] args)
{
//We don't care about waiting for the event to be emitted, so this doesn't need to be async
@@ -387,14 +389,14 @@ namespace ElectronNET.API
socket.OnConnected += (_, __) =>
{
Log("ElectronNET socket connected on port {0}!", BridgeSettings.SocketPort);
_waitForBeingConnected.TrySetResult();
Log("ElectronNET socket connected on port {0}!", BridgeSettings.SocketPort);
};
socket.OnReconnectAttempt += (_, __) =>
{
Log("ElectronNET socket is trying to reconnect on port {0}...", BridgeSettings.SocketPort);
_waitForBeingConnected = new();
Log("ElectronNET socket is trying to reconnect on port {0}...", BridgeSettings.SocketPort);
};
socket.OnReconnectError += (_, ex) =>
@@ -404,8 +406,8 @@ namespace ElectronNET.API
socket.OnReconnected += (_, __) =>
{
Log("ElectronNET socket reconnected on port {0}...", BridgeSettings.SocketPort);
_waitForBeingConnected.TrySetResult();
Log("ElectronNET socket reconnected on port {0}...", BridgeSettings.SocketPort);
};

View File

@@ -37,6 +37,8 @@ namespace ElectronNET.API
}
}
public bool IsConnected => BridgeConnector.IsConnected;
/// <summary>
/// Listens to channel, when a new message arrives listener would be called with
/// listener(event, args...).
@@ -62,7 +64,6 @@ namespace ElectronNET.API
});
}
/// <summary>
/// Listens to channel, when a new message arrives listener would be called with
/// listener(event, args...). This listner will keep the window event sender id