{"id":19251978,"url":"https://github.com/jiangjie/tiny-future","last_synced_at":"2026-01-19T16:33:15.387Z","repository":{"id":251391107,"uuid":"837194790","full_name":"JiangJie/tiny-future","owner":"JiangJie","description":"A zero-dependency Future/Promise wrapper to resolve or reject a Promise outside its executor.","archived":false,"fork":false,"pushed_at":"2026-01-17T15:34:10.000Z","size":164,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-01-18T01:14:29.122Z","etag":null,"topics":["async","await","defer","deferred","future","promise","taskcompletionsource","tiny","withresolvers","zero-dependency"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/JiangJie.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,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-08-02T12:16:48.000Z","updated_at":"2026-01-17T15:34:14.000Z","dependencies_parsed_at":"2024-08-07T03:40:35.196Z","dependency_job_id":"29ec57c6-f677-49fb-ab9b-f4fe487a0fb5","html_url":"https://github.com/JiangJie/tiny-future","commit_stats":null,"previous_names":["jiangjie/tiny-future"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/JiangJie/tiny-future","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JiangJie%2Ftiny-future","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JiangJie%2Ftiny-future/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JiangJie%2Ftiny-future/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JiangJie%2Ftiny-future/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JiangJie","download_url":"https://codeload.github.com/JiangJie/tiny-future/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JiangJie%2Ftiny-future/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28574408,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-19T16:29:19.148Z","status":"ssl_error","status_checked_at":"2026-01-19T16:29:17.772Z","response_time":67,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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","await","defer","deferred","future","promise","taskcompletionsource","tiny","withresolvers","zero-dependency"],"created_at":"2024-11-09T18:24:52.337Z","updated_at":"2026-01-19T16:33:15.382Z","avatar_url":"https://github.com/JiangJie.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# tiny-future\n\n[![License](https://img.shields.io/npm/l/tiny-future.svg)](LICENSE)\n[![Build Status](https://github.com/jiangjie/tiny-future/actions/workflows/test.yml/badge.svg)](https://github.com/jiangjie/tiny-future/actions/workflows/test.yml)\n[![codecov](https://codecov.io/gh/JiangJie/tiny-future/graph/badge.svg)](https://codecov.io/gh/JiangJie/tiny-future)\n[![NPM version](https://img.shields.io/npm/v/tiny-future.svg)](https://npmjs.org/package/tiny-future)\n[![NPM downloads](https://badgen.net/npm/dm/tiny-future)](https://npmjs.org/package/tiny-future)\n[![JSR Version](https://jsr.io/badges/@happy-js/tiny-future)](https://jsr.io/@happy-js/tiny-future)\n[![JSR Score](https://jsr.io/badges/@happy-js/tiny-future/score)](https://jsr.io/@happy-js/tiny-future/score)\n\nA zero-dependency Future/Promise wrapper to resolve or reject a Promise outside its executor.\n\nInspired by C# `TaskCompletionSource`.\n\n## Features\n\n- Zero dependencies\n- TypeScript first with full type support\n- Works with `Promise.withResolvers` (ES2024) with automatic fallback\n- Supports ESM, CommonJS, and Deno/JSR\n\n## Installation\n\n```sh\n# npm\nnpm install tiny-future\n\n# pnpm\npnpm add tiny-future\n\n# yarn\nyarn add tiny-future\n\n# JSR (Deno)\ndeno add @happy-js/tiny-future\n\n# JSR (other runtimes)\nnpx jsr add @happy-js/tiny-future\n```\n\n## Usage\n\n```ts\nimport { Future } from 'tiny-future';\n\nfunction sleep(ms: number): Promise\u003cnumber\u003e {\n    const future = new Future\u003cnumber\u003e();\n\n    setTimeout(() =\u003e {\n        // resolve/reject from anywhere, not just inside the executor\n        future.resolve(ms);\n    }, ms);\n\n    return future.promise;\n}\n\nawait sleep(1000);\n```\n\n### Comparison with standard Promise\n\nWith `Future`, you can resolve or reject from anywhere:\n\n```ts\n// Using Future\nconst future = new Future\u003cstring\u003e();\nsomeAsyncOperation((result) =\u003e {\n    future.resolve(result);\n});\nreturn future.promise;\n```\n\nWith standard `Promise`, resolve/reject must be inside the executor:\n\n```ts\n// Using Promise\nreturn new Promise((resolve) =\u003e {\n    someAsyncOperation((result) =\u003e {\n        resolve(result);\n    });\n});\n```\n\n### Error handling\n\n```ts\nconst future = new Future\u003cvoid\u003e();\n\nfuture.promise.catch((err) =\u003e {\n    console.error('Error:', err.message);\n});\n\nfuture.reject(new Error('something went wrong'));\n```\n\n## API\n\n### `Future\u003cT\u003e`\n\n| Property | Type | Description |\n|----------|------|-------------|\n| `promise` | `Promise\u003cT\u003e` | The underlying Promise instance |\n| `resolve` | `(value: T \\| PromiseLike\u003cT\u003e) =\u003e void` | Resolves the Promise |\n| `reject` | `(reason?: unknown) =\u003e void` | Rejects the Promise |\n\n## Documentation\n\n[API Documentation](https://jiangjie.github.io/tiny-future/)\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjiangjie%2Ftiny-future","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjiangjie%2Ftiny-future","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjiangjie%2Ftiny-future/lists"}