{"id":"cometahn142/promise","name":"promise","scope":"cometahn142","platform":"roblox","description":"Promise For Roblox","version":"0.1.2","latest":"0.1.2","versions":["0.1.0","0.1.1","0.1.2"],"license":"MIT","licenseRating":"safe","licenseCaveats":[],"licenseVerified":true,"dependencies":{},"integrity":"5d173221f39ae46f573f212595ec63a39b533e0bda8b21a065845d551ae53871","likes":0,"downloads":0,"install":"forest install cometahn142/promise","url":"https://forest.dev/p/roblox/cometahn142/promise","files":"https://api.forest.dev/ai/package/roblox/cometahn142/promise/files","readme":"# Promise\n\nPromise is a Promise library for Roblox (Luau) designed to make asynchronous\ncode easier to compose, easier to reason about, and easier to cancel.\n\nRoblox's default async style is mostly based on yielding and resuming threads.\nThat works for small scripts, but it becomes difficult to scale once multiple\nasync operations need to run together, fail independently, or be cancelled when\ntheir result is no longer needed.\n\nThis library takes the Promise approach instead:\n\n- asynchronous work is represented by a value\n- that value can be chained and composed\n- success and failure are handled explicitly\n- cancellation is part of the model\n\n## Why use Promises\n\nPromises help with a few recurring Roblox problems:\n\n- A function may yield unexpectedly, or only sometimes, which makes control\n  flow hard to predict.\n- Running several async tasks together often turns into nested callbacks or\n  repeated success checks.\n- Error handling usually ends up split between `pcall`, tuple returns, and\n  custom conventions.\n- Work that is no longer needed often keeps running unless you clean it up\n  manually.\n\nPromises make those cases more uniform. You create a unit of asynchronous work\nonce, then chain it, combine it, await it, timeout it, or cancel it from one\nplace.\n\n## Features\n\n- Familiar chaining with `andThen`, `catch`, and `finally`\n- Explicit cancellation\n- Timeouts and immediate status inspection\n- Combinators like `all`, `race`, `any`, `allSettled`, and `some`\n- Utility helpers like `each`, `fold`, `retry`, and `retryWithDelay`\n- Structured `Promise.Error` values and unhandled rejection hooks\n\n## Installation\n\n```toml\n[dependencies]\nPromise = \"cometahn142/promise@^0.1\"\n```\n\n## Quick Example\n\n```luau\nlocal Promise = require(Packages.Promise)\n\nlocal function loadProfile(userId)\n\treturn Promise.new(function(resolve, reject)\n\t\ttask.delay(1, function()\n\t\t\tif userId <= 0 then\n\t\t\t\treject(\"Invalid user id\")\n\t\t\t\treturn\n\t\t\tend\n\n\t\t\tresolve({\n\t\t\t\tUserId = userId,\n\t\t\t\tCoins = 100,\n\t\t\t})\n\t\tend)\n\tend)\nend\n\nloadProfile(42)\n\t:andThen(function(profile)\n\t\tprint(\"Loaded profile for\", profile.UserId)\n\t\treturn profile.Coins\n\tend)\n\t:andThen(function(coins)\n\t\tprint(\"Coins:\", coins)\n\tend)\n\t:catch(function(err)\n\t\twarn(\"Profile load failed:\", err)\n\tend)\n```\n\n## Documentation\n\n- [Installation](./docs/installation.md)\n- [Usage Patterns](./docs/usage-patterns.md)\n- [Promise API](./docs/promise.md)\n\n## License\n\nMIT. See `LICENSE`.\n","readmeTruncated":false}