Trans.nvim/lua/Trans/strategy/fallback.lua
2023-05-13 20:04:19 +08:00

28 lines
736 B
Lua

---Fallback query strategy
---@param data TransData
---@return boolean @true if query success
return function(data)
local result = data.result
local update
for _, backend in ipairs(data.backends) do
local name = backend.name
if backend.no_wait then
---@cast backend TransOfflineBackend
backend.query(data)
else
---@cast backend TransOnlineBackend
require 'Trans'.backend.do_query(data, backend)
update = update or data.frontend:wait()
while result[name] == nil and update(backend) do
end
end
---@cast backend TransBackend
if result[name] then return true end
end
return false
end