{"id":31811415,"url":"https://github.com/nvim-java/lua-async","last_synced_at":"2025-10-11T06:48:11.027Z","repository":{"id":211773604,"uuid":"729914636","full_name":"nvim-java/lua-async","owner":"nvim-java","description":"Synchronous like asynchronous with promise like error handling","archived":false,"fork":false,"pushed_at":"2024-03-31T13:33:02.000Z","size":41,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-04-01T14:25:36.432Z","etag":null,"topics":["async","async-await","asynchronous","await-async","coroutines","lua","synchronous"],"latest_commit_sha":null,"homepage":"","language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nvim-java.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2023-12-10T18:31:05.000Z","updated_at":"2024-03-31T13:25:02.000Z","dependencies_parsed_at":"2023-12-13T11:47:25.560Z","dependency_job_id":null,"html_url":"https://github.com/nvim-java/lua-async","commit_stats":null,"previous_names":["nvim-java/lua-async-await"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/nvim-java/lua-async","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nvim-java%2Flua-async","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nvim-java%2Flua-async/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nvim-java%2Flua-async/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nvim-java%2Flua-async/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nvim-java","download_url":"https://codeload.github.com/nvim-java/lua-async/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nvim-java%2Flua-async/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279006444,"owners_count":26084107,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-11T02:00:06.511Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["async","async-await","asynchronous","await-async","coroutines","lua","synchronous"],"created_at":"2025-10-11T06:48:07.821Z","updated_at":"2025-10-11T06:48:11.020Z","avatar_url":"https://github.com/nvim-java.png","language":"Lua","readme":"# lua-async\n\nSynchronous like asynchronous for Lua.\n\n## What\n\nTake a look at before and after\n\n**Before:**\n\n```lua\nrequest('workspace/executeCommand', cmd_info, function(err, res)\n  if err then\n    log.error(err)\n  else\n    log.debug(res)\n  end\nend, buffer)\n```\n\n**After:**\n\n```lua\n-- on error, statement will fail throwing an error just like any synchronous API\nlocal result  = request('workspace/executeCommand', cmd_info, buffer)\nlog.debug(result)\n```\n\n## Why\n\nWell, callback creates callback hell.\n\n## How to use\n\n```lua\nlocal runner = require(\"async.runner\")\nlocal wrap = require(\"async.wrap\")\nlocal wait = require(\"async.waits.wait_with_error_handler\")\n\nlocal function success_async(callback)\n  local timer = vim.loop.new_timer()\n\n  assert(timer)\n\n  timer:start(2000, 0, function()\n    -- First parameter is the error\n    callback(nil, \"hello world\")\n  end)\nend\n\nlocal function fail_async(callback)\n  local timer = vim.loop.new_timer()\n\n  assert(timer)\n\n  timer:start(2000, 0, function()\n    -- First parameter is the error\n    callback(\"something went wrong\", nil)\n  end)\nend\n\nlocal function log(message)\n  vim.print(os.date(\"%H:%M:%S\") .. \" \" .. message)\nend\n\nvim.cmd.messages(\"clear\")\n\nlocal nested = runner(function()\n  local success_sync = wrap(success_async)\n  local fail_sync = wrap(fail_async)\n\n  local success_result = wait(success_sync())\n  -- here we get the result because there is no error\n  log(\"success_result is: \" .. success_result)\n\n  -- following is going to fail and error will get caught by\n  -- the parent runner function's 'catch'\n  wait(fail_sync())\nend)\n\nrunner(function()\n    log(\"starting the execution\")\n    -- just wait for nested runner to complete the execution\n    wait(nested.run)\n  end)\n  .catch(function(err)\n    log(\"parent error handler \" .. err)\n  end)\n  .run()\n```\n\n### Output\n\n```txt\n18:44:46 starting the execution\n18:44:48 success_result is: hello world\n18:44:50 parent error handler ...-async-await/lua/async/waits/wait_with_error_handler.lua:14: ...-async-await/lua/async/waits/wait_with_error_handler.lua:14: something went wrong\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnvim-java%2Flua-async","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnvim-java%2Flua-async","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnvim-java%2Flua-async/lists"}