Skip to content

Commit 284740c

Browse files
authored
fix: avoid error when it exceeds timeout (#539)
When I ran this code, I got an error below. ```lua async.util.block_on(function() async.util.sleep(4000) end) print "done" ``` ```bash E5113: Error while calling lua chunk: /tmp/hoge.lua:4: bad argument #1 to 'block_on' (table expected, got nil) stack traceback: [C]: in function 'block_on' /tmp/hoge.lua:4: in main chunk ``` This means the func is terminated by `vim.wait` and the variable `ret` is still `nil`. So `unpack(ret)` raises an error. This PR fixes this bug by setting a default value for `ret`.
1 parent 5001291 commit 284740c

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

lua/plenary/async/util.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ M.sleep = a.wrap(defer_swapped, 2)
2222
M.block_on = function(async_function, timeout)
2323
async_function = M.protected(async_function)
2424

25-
local stat, ret
25+
local stat
26+
local ret = {}
2627

2728
a.run(async_function, function(stat_, ...)
2829
stat = stat_

0 commit comments

Comments
 (0)