10000 Callbacks will now receive the running job as 'self' by Odie · Pull Request #9 · TravonteD/luajob · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Callbacks will now receive the running job as 'self' #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions lua/luajob.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ local function close_safely(handle)
end
end

local function wrap_ctx(ctx, callback)
return function(err, data)
callback(ctx, err, data)
end
end

function M:new(o)
o = o or {}
for n,f in pairs(o) do
Expand Down Expand Up @@ -72,16 +78,16 @@ function M.options()
return options
end

function M.start()
function M.start(self)
local options = M.options()
M.handle = vim.loop.spawn(options.command,
options,
vim.schedule_wrap(M.shutdown))
vim.schedule_wrap(wrap_ctx(self, M.shutdown)))
if M.on_stdout then
M.stdout:read_start(vim.schedule_wrap(M.on_stdout))
M.stdout:read_start(vim.schedule_wrap(wrap_ctx(self, M.on_stdout)))
end
if M.on_stderr then
M.stderr:read_start(vim.schedule_wrap(M.on_stderr))
M.stderr:read_start(vim.schedule_wrap(wrap_ctx(self, M.on_stderr)))
end
end
return M
0