{"id":13409899,"url":"https://github.com/LPGhatguy/roblox-lua-promise","last_synced_at":"2025-03-14T15:31:02.475Z","repository":{"id":66218263,"uuid":"118976870","full_name":"LPGhatguy/roblox-lua-promise","owner":"LPGhatguy","description":"(NO LONGER MAINTAINED) An implementation of promises akin to JavaScript's Promises/A+","archived":true,"fork":false,"pushed_at":"2019-09-10T04:25:47.000Z","size":30,"stargazers_count":23,"open_issues_count":4,"forks_count":4,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-11T11:51:25.447Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"cc0-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LPGhatguy.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":"2018-01-25T22:50:16.000Z","updated_at":"2024-04-09T00:20:12.000Z","dependencies_parsed_at":null,"dependency_job_id":"a1100384-78b4-4a2c-91a1-48197a52e9ad","html_url":"https://github.com/LPGhatguy/roblox-lua-promise","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LPGhatguy%2Froblox-lua-promise","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LPGhatguy%2Froblox-lua-promise/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LPGhatguy%2Froblox-lua-promise/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LPGhatguy%2Froblox-lua-promise/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LPGhatguy","download_url":"https://codeload.github.com/LPGhatguy/roblox-lua-promise/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243600558,"owners_count":20317298,"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":[],"created_at":"2024-07-30T20:01:03.940Z","updated_at":"2025-03-14T15:31:02.469Z","avatar_url":"https://github.com/LPGhatguy.png","language":"Lua","funding_links":[],"categories":["Tools"],"sub_categories":[],"readme":"# Roblox Lua Promise\nAn implementation of `Promise` similar to Promise/A+.\n\n### This project is no longer maintained. I recommend [evaera's Promise implementation](https://github.com/evaera/roblox-lua-promise), which is a fork that implements cancellation and is actively maintained!\n\n## Motivation\nI've found that being able to yield anywhere causes lots of bugs. In [Rodux](https://github.com/Roblox/Rodux), I explicitly made it impossible to yield in a change handler because of the sheer number of bugs that occured when callbacks randomly yielded.\n\nAs such, I think that Roblox needs an object-based async primitive. It's not important to me whether these are Promises, Observables, Task objects, or Futures.\n\nThe important traits are:\n\n* An object that represents a unit of asynchronous work\n* Composability\n* Predictable timing\n\nThis Promise implementation attempts to satisfy those traits.\n\n## API\n\n### Static Functions\n* `Promise.new((resolve, reject) -\u003e nil) -\u003e Promise`\n\t* Construct a new Promise that will be resolved or rejected with the given callbacks.\n* `Promise.resolve(value) -\u003e Promise`\n\t* Creates an immediately resolved Promise with the given value.\n* `Promise.reject(value) -\u003e Promise`\n\t* Creates an immediately rejected Promise with the given value.\n* `Promise.is(object) -\u003e bool`\n\t* Returns whether the given object is a Promise.\n* `Promise.all(array) -\u003e array`\n\t* Accepts an array of promises and returns a new promise that:\n\t\t* is resolved after all input promises resolve.\n\t\t* is rejected if ANY input promises reject.\n\t* Note: Only the first return value from each promise will be present in the resulting array.\n\n### Instance Methods\n* `Promise:andThen(successHandler, [failureHandler]) -\u003e Promise`\n\t* Chains onto an existing Promise and returns a new Promise.\n\t* Equivalent to the Promise/A+ `then` method.\n* `Promise:catch(failureHandler) -\u003e Promise`\n\t* Shorthand for `Promise:andThen(nil, failureHandler)`.\n* `Promise:await() -\u003e ok, value`\n\t* Yields the current thread until the given Promise completes. Returns `ok` as a bool, followed by the value that the promise returned.\n\n## Example\nThis Promise implementation finished synchronously. In order to wrap an existing async API, you should use `spawn` or `delay` in order to prevent your calling thread from accidentally yielding.\n\n```lua\nlocal HttpService = game:GetService(\"HttpService\")\n\n-- A light wrapper around HttpService\n-- Ideally, you do this once per project per async method that you use.\nlocal function httpGet(url)\n\treturn Promise.new(function(resolve, reject)\n\t\t-- Spawn to prevent yielding, since GetAsync yields.\n\t\tspawn(function()\n\t\t\tlocal ok, result = pcall(HttpService.GetAsync, HttpService, url)\n\n\t\t\tif ok then\n\t\t\t\tresolve(result)\n\t\t\telse\n\t\t\t\treject(result)\n\t\t\tend\n\t\tend)\n\tend)\nend\n\n-- Usage\nhttpGet(\"https://google.com\")\n\t:andThen(function(body)\n\t\tprint(\"Here's the Google homepage:\", body)\n\tend)\n\t:catch(function(err)\n\t\twarn(\"We failed to get the Google homepage!\", err)\n\tend)\n```\n\n## Future Additions\n* `Promise.wrapAsync`\n\t* Intended to wrap an existing Roblox API that yields, exposing a new one that returns a Promise.\n\n## License\nThis project is available under the CC0 license. See [LICENSE](LICENSE) for details.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FLPGhatguy%2Froblox-lua-promise","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FLPGhatguy%2Froblox-lua-promise","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FLPGhatguy%2Froblox-lua-promise/lists"}