5353--- @param url string
5454--- @param opts { headers : table , data : string | table , etag : string , last_modified : string , timeout : string , cmds : table }
5555--- @param cb ? any
56- --- @return vim.SystemCompleted ?
56+ --- @return vim.SystemObj
5757function M .get (url , opts , cb )
5858 opts = opts or {}
5959 opts .timeout = vim .F .if_nil (opts .timeout , " 10" )
@@ -64,7 +64,7 @@ function M.get(url, opts, cb)
6464 user_agent = " feed.nvim/2.0" ,
6565 }, opts .headers or {}))
6666 local dump_fp = vim .fn .tempname ()
67- local cmds = vim .tbl_flatten ({
67+ local cmds = ut .tbl_flatten ({
6868 " curl" ,
6969 req_header ,
7070 " -sSL" ,
@@ -103,8 +103,21 @@ function M.get(url, opts, cb)
103103 return cb and cb (obj ) or obj
104104 end
105105
106- return cb and vim .system (cmds , { text = true }, cb and process or nil )
107- or process (vim .system (cmds , { text = true }):wait ())
106+ if cb then
107+ return vim .system (cmds , { text = true }, cb and process or nil )
108+ else
109+ return setmetatable ({}, {
110+ __index = function (_ , k )
111+ if k == " wait" then
112+ return process (vim .system (cmds , { text = true }):wait ())
113+ end
114+ end ,
115+ })
116+ end
117+
118+ -- TODO: Curl.get just return the vim.system obj, call :wait to sync
119+ -- return cb and vim.system(cmds, { text = true }, cb and process or nil)
120+ -- or process(vim.system(cmds, { text = true }):wait())
108121end
109122
110123--- @async
0 commit comments