src/HarmonyHub/Client.cs
/// <summary>
/// Send a message without waiting for response.
/// </summary>
/// <param name="message">The message to be sent.</param>
/// <param name="timeout">Time to wait for an error response.</param>
/// <returns>A <see cref="Task"/>.</returns>
Send a message without waiting for response.
Send a message without waiting for response .
private async Task FireAndForgetAsync(XmlElement message, int timeout = 50)
        {
            if (!_heartbeat.Enabled)
                throw new ConnectionException("Connection already closed or not authenticated");
            var messageId = message.Attributes["id"].Value;
            var resultTaskCompletionSource = new TaskCompletionSource<XmlElement>();
            _resultTaskCompletionSources[messageId] = resultTaskCompletionSource;
            Send(message);
            var task = await Task.WhenAny(resultTaskCompletionSource.Task, Task.Delay(timeout)).ConfigureAwait(false);
            _resultTaskCompletionSources.Remove(messageId);
            await task.ConfigureAwait(false);
        }
private async Task FireAndForgetAsync ( XmlElement message , int timeout = 50 ) { if ( ! _heartbeat . Enabled ) throw new ConnectionException ( " " ) ; var messageId = message . Attributes [ " " ] . Value ; var resultTaskCompletionSource = new TaskCompletionSource < XmlElement > ( ) ; _resultTaskCompletionSources [ messageId ] = resultTaskCompletionSource ; Send ( message ) ; var task = await Task . WhenAny ( resultTaskCompletionSource . Task , Task . Delay ( timeout ) ) . ConfigureAwait ( false ) ; _resultTaskCompletionSources . Remove ( messageId ) ; await task . ConfigureAwait ( false ) ; }
Send a message without waiting for response.
Send a message without waiting for response .
// Heartbeat check // Prepare the TaskCompletionSource, which is used to await the result // Start the sending // Await, to make sure there wasn't an error // Remove the result task, as we no longer need it. // This makes sure the exception, if there was one, is unwrapped
None
message
XmlElement
The message to be sent.
The message to be sent .
timeout
int
Time to wait for an error response.
Time to wait for an error response .