mirror of
https://github.com/ElectronNET/Electron.NET.git
synced 2026-09-28 09:52:36 +00:00
fix: simplified add/remove of socket listener through usage of "Once"
This commit is contained in:
@@ -218,18 +218,12 @@ namespace ElectronNET.API
|
||||
/// <returns></returns>
|
||||
public async Task<bool> IsDestroyedAsync()
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>();
|
||||
|
||||
BridgeConnector.Socket.On<bool>("tray-isDestroyedCompleted", (isDestroyed) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("tray-isDestroyedCompleted");
|
||||
|
||||
taskCompletionSource.SetResult(isDestroyed);
|
||||
});
|
||||
var tcs = new TaskCompletionSource<bool>();
|
||||
|
||||
BridgeConnector.Socket.Once<bool>("tray-isDestroyedCompleted", tcs.SetResult);
|
||||
await BridgeConnector.Socket.Emit("tray-isDestroyed").ConfigureAwait(false);
|
||||
|
||||
return await taskCompletionSource.Task.ConfigureAwait(false);
|
||||
return await tcs.Task.ConfigureAwait(false);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user