Mixing sync and callback-based code

Hello there!

I’m writing my first IO- and UI-heavy plugin and bit confused on how to communicate between sync and async functions.

For example, I have following code:

function telescopePicker(opts)
  local url = askUser()      // this one is async, using vim.ui.input; variable just as an example
  local req = cur.get(url)   // also typically async
  return pickers.new(opts, req)   // this is always sync and final result must be of known type

In other languages I’d use something like Promise or IO monad and block and the last stage, but it seems there’s nothing like that in Neovim Lua community?

1 Like

@chuwy did you find a good solution here? I’m also struggling trying to have a function that calls vim.ui.input and returns a synchronous final result.

Maybe you can use coroutine to control the flow: futures