/// <summary> /// Waits for a match to a specific request, else returns null. /// </summary> /// <param name="request">Request to match</param> /// <returns></returns> public async Task <T> WaitForMatch(MatchRequest <T> request) { T result = null; this._matchrequests.Add(request); try { result = await request._tcs.Task.ConfigureAwait(false); } catch (Exception ex) { this._client.Logger.LogError(InteractivityEvents.InteractivityWaitError, ex, "An exception occurred while waiting for {0}", typeof(T).Name); } finally { request.Dispose(); this._matchrequests.TryRemove(request); } return(result); }
/// <summary> /// Waits for a match to a specific request, else returns null. /// </summary> /// <param name="request">Request to match</param> /// <returns></returns> public async Task <T> WaitForMatch(MatchRequest <T> request) { T result = null; this._matchrequests.Add(request); try { result = await request._tcs.Task; } catch (Exception ex) { this._client.DebugLogger.LogMessage(LogLevel.Error, "Interactivity", $"Something went wrong waiting for {typeof(T).Name} with exception {ex.GetType().Name}.", DateTime.Now); } finally { request.Dispose(); this._matchrequests.TryRemove(request); } return(result); }