internal static void RecordLatency(EndpointDiagnostics endpoint, Action action) { var timer = Stopwatch.StartNew(); try { action(); endpoint.State = ServiceState.Ok; } catch { endpoint.State = ServiceState.Error; } endpoint.Latency = timer.ElapsedTicks / TicksPerMicrosecond; }
internal static async Task RecordLatencyAsync(EndpointDiagnostics endpoint, Func <Task> action) { var timer = Stopwatch.StartNew(); try { await action().ConfigureAwait(false); endpoint.State = ServiceState.Ok; } catch (Exception) { endpoint.State = ServiceState.Error; } endpoint.Latency = timer.ElapsedTicks / TicksPerMicrosecond; }