{"id":20743081,"url":"https://github.com/aimingoo/promise","last_synced_at":"2025-04-24T05:17:09.658Z","repository":{"id":36168795,"uuid":"40472892","full_name":"aimingoo/Promise","owner":"aimingoo","description":"Promise module in Lua, ES6 Promises full supported.","archived":false,"fork":false,"pushed_at":"2020-03-29T14:15:46.000Z","size":16,"stargazers_count":21,"open_issues_count":0,"forks_count":8,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-24T05:16:52.734Z","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":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aimingoo.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}},"created_at":"2015-08-10T08:57:16.000Z","updated_at":"2024-03-09T05:09:13.000Z","dependencies_parsed_at":"2022-07-25T19:48:15.393Z","dependency_job_id":null,"html_url":"https://github.com/aimingoo/Promise","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aimingoo%2FPromise","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aimingoo%2FPromise/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aimingoo%2FPromise/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aimingoo%2FPromise/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aimingoo","download_url":"https://codeload.github.com/aimingoo/Promise/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250566523,"owners_count":21451234,"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-11-17T07:09:00.519Z","updated_at":"2025-04-24T05:17:09.634Z","avatar_url":"https://github.com/aimingoo.png","language":"Lua","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Promise\nThe Promise module in Lua. Simple, Fast and ES6 Promises full supported/compatibled.\n\nAbout ES6 Promises see here: [Promise in MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)\n\nA chinese document at here: [The Promise's World](http://blog.csdn.net/aimingoo/article/details/47401961)\n\n### Table of Contents\n\n* [Install \u0026amp; Usage](#install--usage)\n* [Interface](#interface)\n* [testcase or samples](#testcase-or-samples)\n* [History](#history)\n\n\n# Install \u0026 Usage\nDownload the file `Promise.lua` and put it into lua search path or current directory, and load as module from lua.\n\nOr use luarocks and require as module:\n\n```bash\n\u003e luarocks install promise-es6\n```\n\nand, use `Promise.new()` or use `Promise.xxx` method to get promise object.\n\n```lua\nPromise = require('Promise')\n\np1 = Promise.new(function(resolve, reject)\n  resolve('your immediate value, or result from remote query or asynchronous call')\nend)\n\np2 = Promise.resolve('immediate value')\n\np1:andThen(function(value)\n  print(value)\n  return 'something'\nend):andThen(..)   -- more\n```\n\n# Interface\n\n* **For the Promsie class, call with '.'**\n\n**Promise.new(executor)**\n\n\u003e ```lua\n\u003e promise = Promise.new(function(resolve, reject) .. end);\n\u003e ```\n\n**Promise.all(array)**\n\n\u003e ```\n\u003e promise = Promise.all(array)\t-- a table as array\n\u003e ```\n\n**Promise.race(array)**\n\n\u003e ```lua\n\u003e promise = Promise.race(array)\t-- a table as array\n\u003e ```\n\n**Promise.reject(reason)**\n\n\u003e ```lua\n\u003e promise = Promise.reject(reason);\t-- reason is anything\n\u003e ```\n\n**Promise.resolve(value)**\n\n\u003e ```lua\n\u003e promise = Promise.resolve(value);\n\u003e promise = Promise.resolve(thenable);\n\u003e promise = Promise.resolve(promise);\n\u003e ```\n\n* **For promise instance, call with ':'**\n\n**promise:andThen(onFulfilled, onRejected)**\n\n\u003e ```lua\n\u003e promise2 = promise:andThen(functoin(value) ... end);\n\u003e promise2 = promise:andThen(nil, functoin(reson) ... end);\n\u003e ```\n\n**promise:catch(onRejected)**\n\n\u003e ```lua\n\u003e promise2 = promise:catch(functoin(reson) ... end)\n\u003e ```\n\n# testcase or samples\n\nThis is a base testcase:\n\n```lua\n---\n--- from testcase/t_base_test.lua\n---\nPromise = require('Promise')\n\nA = function() return 10 end\nB = function(a) print(a * 2) end\nC = function(a)\n\tprint(a * 4)\n\treturn Promise.resolve('ok')  -- or direct return 'ok'\nend\nD = function(a) print(a * 3) end\nE = function(result)\n\tlocal b, c, d = unpack(result)\n\tprint(b, c, d)\n\treturn Promise.reject('FIRE')\nend\n\n-- promise_A = Promise.resolve(A())\npromise_A = Promise.new(function(resolve, reject)\n\tlocal ok, result = pcall(A)\n\treturn (ok and resolve or reject)(result)\nend)\npromise_B = promise_A:andThen(B)\npromise_C = promise_A:andThen(C)\npromise_D = promise_A:andThen(D)\n\npromises = {promise_B, promise_C, promise_D}\nPromise.all(promises)\n\t:andThen(E)\n\t:catch(function(reson)\n\t\tprint(reson)\n\tend)\n```\n\n# History\n\n* 2017.04.26\trelease v1.2, fix some bugs\n\n```\n\t- fix bug: value deliver on promise chain, about issue-#3, thanks for @stakira\n\t- ignore rewrite promised value\n```\n\n* 2015.10.29\trelease v1.1, fix some bugs\n\n```\n \t- update testcases\n \t- update: add .catch() for promised string\n \t- update: protect call in .new method\n \t- fix bug: resolver values when multi call .then()\n \t- fix bug: non standard .reject() implement\n \t- fix bug: some error in .all() and .race() methods\n```\n\n* 2015.08.10\trelease v1.0.1, full testcases, minor fix and publish on github\n\n* 2015.03\trelease v1.0.0\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faimingoo%2Fpromise","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faimingoo%2Fpromise","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faimingoo%2Fpromise/lists"}