{"id":20610567,"url":"https://github.com/kevinhwang91/promise-async","last_synced_at":"2025-06-18T08:41:14.083Z","repository":{"id":45208612,"uuid":"472705760","full_name":"kevinhwang91/promise-async","owner":"kevinhwang91","description":"Promise \u0026 Async in Lua","archived":false,"fork":false,"pushed_at":"2024-08-04T23:18:38.000Z","size":75,"stargazers_count":146,"open_issues_count":0,"forks_count":6,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-05-27T08:54:43.018Z","etag":null,"topics":["async","async-await","eventloop","libuv","lua","luv","neovim","promise"],"latest_commit_sha":null,"homepage":"","language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kevinhwang91.png","metadata":{"files":{"readme":"README.md","changelog":null,"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,"publiccode":null,"codemeta":null}},"created_at":"2022-03-22T09:58:03.000Z","updated_at":"2025-05-26T14:58:02.000Z","dependencies_parsed_at":"2024-02-27T06:32:40.228Z","dependency_job_id":"86535253-7f3c-4b05-bb6b-592b2ffe4258","html_url":"https://github.com/kevinhwang91/promise-async","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/kevinhwang91/promise-async","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinhwang91%2Fpromise-async","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinhwang91%2Fpromise-async/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinhwang91%2Fpromise-async/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinhwang91%2Fpromise-async/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kevinhwang91","download_url":"https://codeload.github.com/kevinhwang91/promise-async/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinhwang91%2Fpromise-async/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260521265,"owners_count":23021782,"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","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","eventloop","libuv","lua","luv","neovim","promise"],"created_at":"2024-11-16T10:17:13.923Z","updated_at":"2025-06-18T08:41:09.069Z","avatar_url":"https://github.com/kevinhwang91.png","language":"Lua","funding_links":[],"categories":["Lua"],"sub_categories":[],"readme":"# promise-async\n\n![GitHub Test](https://github.com/kevinhwang91/promise-async/workflows/Test/badge.svg)\n![GitHub Lint](https://github.com/kevinhwang91/promise-async/workflows/Lint/badge.svg)\n\nThe goal of promise-async is to port [Promise][promise] \u0026 [Async][async] from JavaScript to Lua.\n\n\u003e A value returned by async function in JavaScript is actually a Promise Object. It's incomplete and\n\u003e inflexible for using an async function wrapped by bare coroutine without Promise in almost Lua\n\u003e implementation.\n\n- [Features](#features)\n- [Demonstration](#demonstration)\n  - [Script](#script)\n    - [demo.lua](#demo.lua)\n    - [demo.js](#demo.js)\n- [Quickstart](#quickstart)\n  - [Requirements](#requirements)\n  - [Installation](#installation)\n    - [As a plugin for Neovim platform](#as-a-plugin-for-neovim-platform)\n    - [As a library from Luarocks](#as-a-library-from-luarocks)\n- [Documentation](#documentation)\n  - [Summary](#summary)\n  - [async](#async)\n- [Development](#development)\n  - [Neovim tips](#neovim-tips)\n  - [Run tests](#run-tests)\n  - [Improve completion experience](#improve-completion-experience)\n  - [Customize EventLoop](#customize-eventloop)\n- [Credit](#credit)\n- [Feedback](#feedback)\n- [License](#license)\n\n## Features\n\n- API is similar to JavaScript's\n- Customize EventLoop in any platforms\n- Support Lua 5.1-5.4 and LuaJIT with an EventLoop module\n- Support Neovim platform\n\n## Demonstration\n\n\u003chttps://user-images.githubusercontent.com/17562139/169118448-9468909b-dbde-4dde-9308-ffe71abb24cd.mp4\u003e\n\n### Script\n\n#### demo.lua\n\n\u003chttps://github.com/kevinhwang91/promise-async/blob/3f6dcb2f0f546e8be7e170785f07f71ef6afab34/examples/demo.lua#L17-L82\u003e\n\n#### demo.js\n\n\u003chttps://github.com/kevinhwang91/promise-async/blob/3f6dcb2f0f546e8be7e170785f07f71ef6afab34/examples/demo.js#L1-L58\u003e\n\n## Quickstart\n\n### Requirements\n\n- Lua 5.1 or latter\n- [Luv](https://github.com/luvit/luv)\n\n\u003e Luv is a default EventLoop for promise-async. It doesn't mean promise-async must require it. In\n\u003e fact, promise-async require a general EventLoop module which Luv like.\n\n### Installation\n\n#### As a plugin for Neovim platform\n\nInstall with [Packer.nvim](https://github.com/wbthomason/packer.nvim):\n\n- As a normal plugin\n\n```lua\nuse {'kevinhwang91/promise-async'}\n```\n\nor\n\n- As a Luarocks plugin\n\n```lua\nuse_rocks {'promise-async'}\n```\n\n#### As a library from Luarocks\n\n1. `luarocks install promise-async`\n2. `luarocks install luv` or implement an EventLoop\n   [interface](https://github.com/kevinhwang91/promise-async/blob/main/typings/loop.lua) to adapt\n   your platform\n\n## Documentation\n\npromise-async's API is based on [MDN-Promise][promise]. [typings/promise.lua](typings/promise.lua)\nis the typings with documentation of Promise class.\n\n### Summary\n\nSummary up the API different from JavaScript.\n\n\u003c!-- markdownlint-disable MD013 --\u003e\n\n| JavaScript                                          | Lua                                             |\n| --------------------------------------------------- | ----------------------------------------------- |\n| `new Promise`                                       | `Promise:new`/`Promise`                         |\n| `Promise.then`                                      | `Promise:thenCall`, `then` is language keyword  |\n| `Promise.catch`                                     | `Promise:catch`                                 |\n| `Promise.finally`                                   | `Promise:finally`                               |\n| `Promise.resolve`                                   | `Promise.resolve`                               |\n| `Promise.reject`                                    | `Promise.reject`                                |\n| `Promise.all`: `Symbol.iterator` as iterator        | `Promise.all`: `pairs` as iterator              |\n| `Promise.allSettled`: `Symbol.iterator` as iterator | `Promise.allSettled`: `pairs` as iterator       |\n| `Promise.any`: `Symbol.iterator` as iterator        | `Promise.any`: `pairs` as iterator              |\n| `Promise.race`: `Symbol.iterator` as iterator       | `Promise.race`: `pairs` as iterator             |\n| `async`: as keyword at the start of a function      | `Async`/`Async.sync`: as a surrounding function |\n| `await`: as keyword                                 | `await`/`Async.wait` as a function              |\n\n\u003c!-- markdownlint-enable MD013 --\u003e\n\n### async\n\nThe environment in `Async.sync` function have been injected some new functions for compatibility or\nenhancement:\n\n1. `await`: A reference of `Async.wait` function;\n2. `pcall`: Be compatible with LuaJIT;\n3. `xpcall`: Be compatible with LuaJIT;\n\n`async` in JavaScript return Promise object only with single result, but may carry multiple results\nin Lua. The resolved result of Promise object return by `async` function will be packed into a table\nvia `{...}`. However, the result handled by `await` will be unpacked and return multiple values.\n\n```lua\nlocal async = require('async')\n\nlocal function f()\n    return 1, 2, 3\nend\n\n-- multiple results are packed into resolved result in Promise\nasync(f):thenCall(function(v)\n    print(v[1], v[2], v[3]) -- output: 1 2 3\nend)\n\n-- results returned by `await`\nasync(function()\n    local v1, v2, v3 = await(async(f))\n    print(v1, v2, v3) -- output: 1 2 3\nend)\n\nuv.run()\n```\n\n## Development\n\n### Neovim tips\n\n- `Promise.resolve():thenCall(cb)` is almost equivalent to `vim.schedule(cb)`.\n\n### Run tests\n\n`make test`\n\n### Improve completion experience\n\nFollowing [typings/README.md](./typings/README.md)\n\n### Customize EventLoop\n\nTODO, refer to [loop.lua](./lua/promise-async/loop.lua)\n\n## Credit\n\n- [Promise][promise]\n- [Async][async]\n- [promises-tests](https://github.com/promises-aplus/promises-tests)\n- [then/promise](https://github.com/then/promise)\n- [promisejs.org](https://www.promisejs.org)\n- [event-loop-timers-and-nexttick](https://nodejs.org/en/docs/guides/event-loop-timers-and-nexttick)\n\n[promise]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise\n[async]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function\n\n## Feedback\n\n- If you get an issue or come up with an awesome idea, don't hesitate to open an issue in github.\n- If you think this plugin is useful or cool, consider rewarding it a star.\n\n## License\n\nThe project is licensed under a BSD-3-clause license. See [LICENSE](./LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkevinhwang91%2Fpromise-async","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkevinhwang91%2Fpromise-async","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkevinhwang91%2Fpromise-async/lists"}