{"id":13733225,"url":"https://github.com/sindresorhus/p-lazy","last_synced_at":"2025-05-15T14:06:56.583Z","repository":{"id":50311139,"uuid":"73060555","full_name":"sindresorhus/p-lazy","owner":"sindresorhus","description":"Create a lazy promise that defers execution until it's awaited or when .then() or .catch() is called","archived":false,"fork":false,"pushed_at":"2024-10-28T06:52:02.000Z","size":23,"stargazers_count":273,"open_issues_count":1,"forks_count":11,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-05-07T16:29:19.108Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/sindresorhus.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":".github/security.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"sindresorhus","open_collective":"sindresorhus","buy_me_a_coffee":"sindresorhus","custom":"https://sindresorhus.com/donate"}},"created_at":"2016-11-07T09:05:39.000Z","updated_at":"2025-05-05T21:28:36.000Z","dependencies_parsed_at":"2024-11-05T23:49:22.067Z","dependency_job_id":null,"html_url":"https://github.com/sindresorhus/p-lazy","commit_stats":{"total_commits":21,"total_committers":5,"mean_commits":4.2,"dds":"0.23809523809523814","last_synced_commit":"a87a0418fc7e6d977b66a372d2726d5730901181"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fp-lazy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fp-lazy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fp-lazy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fp-lazy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sindresorhus","download_url":"https://codeload.github.com/sindresorhus/p-lazy/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253661161,"owners_count":21943871,"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-08-03T03:00:39.722Z","updated_at":"2025-05-15T14:06:56.534Z","avatar_url":"https://github.com/sindresorhus.png","language":"JavaScript","funding_links":["https://github.com/sponsors/sindresorhus","https://opencollective.com/sindresorhus","https://buymeacoffee.com/sindresorhus","https://sindresorhus.com/donate"],"categories":["Packages","JavaScript","Convenience Utilities"],"sub_categories":["sindresorhus's many Promise utilities ([see notes](https://github.com/sindresorhus/promise-fun))","sindresorhus's many Promise utilities (\u003cb\u003e\u003ccode\u003e\u0026nbsp;\u0026nbsp;5157⭐\u003c/code\u003e\u003c/b\u003e \u003cb\u003e\u003ccode\u003e\u0026nbsp;\u0026nbsp;\u0026nbsp;138🍴\u003c/code\u003e\u003c/b\u003e [see notes](https://github.com/sindresorhus/promise-fun)))"],"readme":"# p-lazy\n\n\u003e Create a lazy promise that defers execution until it's awaited or when `.then()`, or `.catch()`, or `.finally()` is called\n\nUseful if you're doing some heavy operations and would like to only do it when the promise is actually used.\n\n## Install\n\n```sh\nnpm install p-lazy\n```\n\n## Usage\n\n```js\nimport PLazy from 'p-lazy';\n\nconst lazyPromise = new PLazy(resolve =\u003e {\n\tsomeHeavyOperation(resolve);\n});\n\n// `someHeavyOperation` is not yet called\n\nawait doSomethingFun;\n\n// `someHeavyOperation` is called\nconsole.log(await lazyPromise);\n```\n\n## API\n\n### new PLazy(executor)\n\nSame as the [`Promise` constructor](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Promise). `PLazy` is a subclass of `Promise`.\n\n### PLazy.from(fn)\n\nCreate a `PLazy` promise from a promise-returning or async function.\n\n### PLazy.resolve(value)\n\nCreate a `PLazy` promise that is resolved with the given `value`, or the promise passed as `value`.\n\n### PLazy.reject(reason)\n\nCreate a `PLazy` promise that is rejected with the given `reason`.\n\n## Related\n\n- [p-cancelable](https://github.com/sindresorhus/p-cancelable) - Create a promise that can be canceled\n- [p-defer](https://github.com/sindresorhus/p-defer) - Create a deferred promise\n- [lazy-value](https://github.com/sindresorhus/lazy-value) - Create a lazily evaluated value\n- [define-lazy-prop](https://github.com/sindresorhus/define-lazy-prop) - Define a lazily evaluated property on an object\n- [More…](https://github.com/sindresorhus/promise-fun)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Fp-lazy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsindresorhus%2Fp-lazy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Fp-lazy/lists"}