refactor: support async online query engine:baidu

This commit is contained in:
JuanZoran
2023-03-09 22:55:04 +08:00
parent eb6e93c24b
commit da1f847bd0
7 changed files with 120 additions and 118 deletions

View File

@ -60,7 +60,7 @@ return {
-- no = '❌'
},
theme = 'default',
db_path = '$HOME/.vim/dict/ultimate.db',
dir = '$HOME/.vim/dict',
-- float = {
-- width = 0.8,
-- height = 0.8,

View File

View File

@ -24,10 +24,22 @@ process = function(opts)
end
local res = require('Trans.backend').offline.query(data)
-- vim.pretty_print(res)
require('Trans.backend').baidu.query(data)
local thread = coroutine.running()
local resume = function()
coroutine.resume(thread)
end
local time = 0
while data.result == nil do
vim.defer_fn(resume, 400)
time = time + 1
print('waiting' .. ('.'):rep(time))
coroutine.yield()
end
vim.pretty_print(data)
M.translate = coroutine.wrap(process)
end
return process
return coroutine.wrap(process)