blob: 33fa9957ad30e5c51fd1c9f0a4cff8481149efb6 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
local a = require "plenary.async"
local assert = require "luassert"
local function wait_for(_, arguments)
---@type fun() @Function to execute until it does not error.
local assertions_fn = arguments[1]
---@type number @Timeout in milliseconds. Defaults to 5000.
local timeout = arguments[2]
timeout = timeout or 15000
local start = vim.loop.hrtime()
local is_ok, err
repeat
is_ok, err = pcall(assertions_fn)
if not is_ok then
a.util.sleep(math.min(timeout, 100))
end
until is_ok or ((vim.loop.hrtime() - start) / 1e6) > timeout
if not is_ok then
error(err)
end
return is_ok
end
assert:register("assertion", "wait_for", wait_for)
|