Skip to content

Instantly share code, notes, and snippets.

@hrsh7th
Last active October 23, 2022 07:59
Show Gist options
  • Save hrsh7th/be5d580aaee4105c71ff32897fa4b3be to your computer and use it in GitHub Desktop.
Save hrsh7th/be5d580aaee4105c71ff32897fa4b3be to your computer and use it in GitHub Desktop.
neovim lua parallel
-- You can also use require('mpack') for data serialization between server and client.
local uv = require "luv"
local SOCK = string.format("/tmp/server-%s.sock", os.clock())
uv.new_thread(function(sock)
local uv = require "luv"
local server = uv.new_pipe(false)
server:bind(sock)
server:listen(128, function()
local client = uv.new_pipe(false)
server:accept(client)
client:read_start(function(_, chunk)
client:write(chunk .. chunk)
end)
end)
uv.run("default")
end, SOCK)
-- You can also use `uv.new_async` for waiting server process.
vim.wait(100, function()
return uv.fs_stat(SOCK)
end)
local client = uv.new_pipe(false)
client:connect(SOCK, function(err)
if err then
error(err)
end
client:read_start(function(_, chunk)
print(chunk)
end)
client:write("aiueo")
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment