From 349c5382eb78dfce06e58721a13d9cbaafac452c Mon Sep 17 00:00:00 2001 From: Chip Senkbeil Date: Thu, 7 Oct 2021 00:00:34 -0500 Subject: [PATCH] Include neovim example --- distant-lua/README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/distant-lua/README.md b/distant-lua/README.md index 47c9be0..0e309d1 100644 --- a/distant-lua/README.md +++ b/distant-lua/README.md @@ -59,6 +59,24 @@ read_dir(session, { path = "path/to/dir" }, function(success, result) print(result) end end) + +-- For neovim, there exists a helper function that converts async functions +-- into functions that take callbacks, executing the asynchronous logic +-- using neovim's event loop powered by libuv +local read_dir = distant.utils.nvim_wrap_async(session.read_dir_async) +read_dir(session, { path = "path/to/dir" }, function(success, result) + -- success: Returns true if ok and false if err + -- result: If success is true, then is the resulting value, + -- otherwise is the error + print("Success", success) + if success then + for _, entry in ipairs(result.entries) do + print("Entry", entry.file_type, entry.path, entry.depth) + end + else + print(result) + end +end) ``` ## Tests