From 9cd1fd09c0619df91cd65c71f866fcc2a9050d6e Mon Sep 17 00:00:00 2001 From: Dung Huynh Duc Date: Tue, 30 Jul 2024 23:28:56 +0800 Subject: [PATCH] feat: add response time calculation to hurl requests --- lua/hurl/main.lua | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lua/hurl/main.lua b/lua/hurl/main.lua index 223be90..5038b52 100644 --- a/lua/hurl/main.lua +++ b/lua/hurl/main.lua @@ -7,6 +7,7 @@ local M = {} local response = {} local head_state = '' local is_running = false +local start_time = nil --- Convert from --json flag to same format with other command local function convert_headers(headers) @@ -35,7 +36,7 @@ local on_json_output = function(code, data, event) local result = vim.json.decode(data[1]) utils.log_info('hurl: json result ' .. vim.inspect(result)) - response.time = result.time + response.response_time = result.time -- TODO: It might have more than 1 entry, so we need to handle it if @@ -137,6 +138,7 @@ local function execute_hurl_cmd(opts, callback) end is_running = true + start_time = vim.loop.hrtime() -- Capture the start time spinner.show() head_state = '' utils.log_info('hurl: running request') @@ -217,6 +219,10 @@ local function execute_hurl_cmd(opts, callback) utils.log_info('hurl: request finished') utils.notify('hurl: request finished', vim.log.levels.INFO) + -- Calculate the response time + local end_time = vim.loop.hrtime() + response.response_time = (end_time - start_time) / 1e6 -- Convert to milliseconds + if callback then return callback(response) else