From c472f3ea46a5dd5f62bb12b5857e779ae0d74dc5 Mon Sep 17 00:00:00 2001 From: William Boman Date: Sat, 16 Apr 2022 01:43:09 +0200 Subject: fix(async): slightly better support for nested coroutine contexts (#600) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(async): only dispatch first failure in a.wait_all * add InstallContext:run_concurrently This is needed due to how multiple coroutine contexts are used in a hierchical structure, and the async coroutine dispatcher loses this hierchical context inside callback functions invoked via FFI (I… assume?). --- lua/nvim-lsp-installer/core/installer/context.lua | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'lua/nvim-lsp-installer/core/installer/context.lua') diff --git a/lua/nvim-lsp-installer/core/installer/context.lua b/lua/nvim-lsp-installer/core/installer/context.lua index 5705fa41..f97f334f 100644 --- a/lua/nvim-lsp-installer/core/installer/context.lua +++ b/lua/nvim-lsp-installer/core/installer/context.lua @@ -4,6 +4,8 @@ local fs = require "nvim-lsp-installer.core.fs" local path = require "nvim-lsp-installer.path" local platform = require "nvim-lsp-installer.platform" local receipt = require "nvim-lsp-installer.core.receipt" +local installer = require "nvim-lsp-installer.core.installer" +local a = require "nvim-lsp-installer.core.async" ---@class ContextualSpawn ---@field cwd CwdManager @@ -139,4 +141,17 @@ function InstallContext:promote_cwd() self.cwd:set(self.destination_dir) end +---Runs the provided async functions concurrently and returns their result, once all are resolved. +---This is really just a wrapper around a.wait_all() that makes sure to patch the coroutine context before creating the +---new async execution contexts. +---@async +---@param suspend_fns async fun(ctx: InstallContext)[] +function InstallContext:run_concurrently(suspend_fns) + return a.wait_all(vim.tbl_map(function(suspend_fn) + return function() + return installer.run_installer(self, suspend_fn) + end + end, suspend_fns)) +end + return InstallContext -- cgit v1.2.3-70-g09d2