Skip to content

Commit

Permalink
feat: add response time calculation to hurl requests
Browse files Browse the repository at this point in the history
  • Loading branch information
jellydn committed Jul 30, 2024
1 parent c138133 commit 9cd1fd0
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lua/hurl/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9cd1fd0

Please sign in to comment.