{"id":28684875,"url":"https://github.com/node-modules/ready-callback","last_synced_at":"2025-06-14T03:07:23.922Z","repository":{"id":26796454,"uuid":"30254877","full_name":"node-modules/ready-callback","owner":"node-modules","description":"Launch server after all async task ready","archived":false,"fork":false,"pushed_at":"2023-10-11T02:30:26.000Z","size":75,"stargazers_count":26,"open_issues_count":0,"forks_count":6,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-12T18:56:00.643Z","etag":null,"topics":["ready"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/node-modules.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"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":"2015-02-03T17:20:39.000Z","updated_at":"2023-10-11T02:30:48.000Z","dependencies_parsed_at":"2024-06-18T15:26:03.885Z","dependency_job_id":"248c4f31-b7b1-471c-9458-bfa4c87c9473","html_url":"https://github.com/node-modules/ready-callback","commit_stats":null,"previous_names":["node-modules/ready-callback","koajs/koa-ready","alibaba-archive/ready-callback"],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/node-modules/ready-callback","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/node-modules%2Fready-callback","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/node-modules%2Fready-callback/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/node-modules%2Fready-callback/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/node-modules%2Fready-callback/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/node-modules","download_url":"https://codeload.github.com/node-modules/ready-callback/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/node-modules%2Fready-callback/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259522456,"owners_count":22870469,"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":["ready"],"created_at":"2025-06-14T03:07:22.377Z","updated_at":"2025-06-14T03:07:23.916Z","avatar_url":"https://github.com/node-modules.png","language":"TypeScript","readme":"# ready-callback\n\n[![NPM version][npm-image]][npm-url]\n[![CI](https://github.com/node-modules/ready-callback/actions/workflows/nodejs.yml/badge.svg)](https://github.com/node-modules/ready-callback/actions/workflows/nodejs.yml)\n[![Test coverage][codecov-image]][codecov-url]\n[![npm download][download-image]][download-url]\n\n[npm-image]: https://img.shields.io/npm/v/ready-callback.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/ready-callback\n[codecov-image]: https://codecov.io/github/node-modules/ready-callback/coverage.svg?branch=master\n[codecov-url]: https://codecov.io/github/node-modules/ready-callback?branch=master\n[download-image]: https://img.shields.io/npm/dm/ready-callback.svg?style=flat-square\n[download-url]: https://npmjs.org/package/ready-callback\n\nLaunch server after all async task ready\n\n---\n\n## Install\n\n```bash\n$ npm install ready-callback\n```\n\n## Usage\n\n**Note: ready-callback is using `class`, so you should use node\u003e=2**\n\n```js\nvar koa = require('koa');\nvar ready = require('ready-callback')();\nvar app = koa();\nready.mixin(app);\n\n// register a service\nvar done = app.readyCallback('service');\nserviceLaunch(done);\n\n// callback will be fired after all service launched\napp.ready(function() {\n  app.listen();\n});\n```\n\n### Error Handle\n\nIf task is called with error, `error` event will be emit, `ready` will never be called.\n\n```js\n// register a service that will emit error\nvar done = app.readyCallback('service');\nserviceLaunch(function(err) {\n  done(err);\n});\n\n// listen error event\napp.on('error', function(err) {\n  // catch error\n});\n```\n\n### Weak Dependency\n\nIf you set a task weak dependency, task will be done without emit `error`.\n\n```js\nvar done = app.readyCallback('service', {isWeakDep: true});\nserviceLaunch(function(err) {\n  done(err);\n});\n\n// will be ready\napp.ready(function() {\n  app.listen();\n});\n\napp.on('error', function(err) {\n  // never be called\n});\n```\n\nYou can also set for all ready-callback\n\n```js\nvar ready = require('ready-callback')({isWeakDep: true});\n```\n\n### Ready Status\n\nYou can get status every callback end.\n\n```js\napp.on('ready_stat', function(data) {\n  console.log(data.id); // id of the ended task\n  console.log(data.remain); // tasks waiting to be ended\n});\n```\n\n### Timeout\n\nYou can set timeout when a task run a long time.\n\n```js\nvar ready = require('ready-callback')({timeout: 1000});\nready.mixin(app);\napp.on('ready_timeout', function(id) {\n  // this will be called after 1s that `service` task don't complete\n});\n\nvar done = app.readyCallback('service');\nserviceLaunch(function() {\n  // run a long time\n  done();\n});\n```\n\nYou can also set timeout for every task\n\n```js\nready.mixin(app);\napp.on('ready_timeout', function(id) {\n  // this will be called after 1s that `service` task don't complete\n});\n\nvar done = app.readyCallback('service1', {timeout: 1000});\nserviceLaunch(done);\n```\n\n### lazyStart\n\nYou can set a ready-callback object to lazyStart. It will not check \nready status immediately, and should start manualy to check ready \nstatus.\n\n```js\nvar ready = require('ready-callback')({ lazyStart: true });\nyield sleep(1);\n// ready obj is not ready\nready.start();\nyield sleep(1);\n// ready obj is ready now\n```\n\n## LISENCE\n\nCopyright (c) 2015 popomore. Licensed under the MIT license.\n\n\u003c!-- GITCONTRIBUTOR_START --\u003e\n\n## Contributors\n\n|[\u003cimg src=\"https://avatars.githubusercontent.com/u/360661?v=4\" width=\"100px;\"/\u003e\u003cbr/\u003e\u003csub\u003e\u003cb\u003epopomore\u003c/b\u003e\u003c/sub\u003e](https://github.com/popomore)\u003cbr/\u003e|[\u003cimg src=\"https://avatars.githubusercontent.com/u/156269?v=4\" width=\"100px;\"/\u003e\u003cbr/\u003e\u003csub\u003e\u003cb\u003efengmk2\u003c/b\u003e\u003c/sub\u003e](https://github.com/fengmk2)\u003cbr/\u003e|[\u003cimg src=\"https://avatars.githubusercontent.com/u/32174276?v=4\" width=\"100px;\"/\u003e\u003cbr/\u003e\u003csub\u003e\u003cb\u003esemantic-release-bot\u003c/b\u003e\u003c/sub\u003e](https://github.com/semantic-release-bot)\u003cbr/\u003e|[\u003cimg src=\"https://avatars.githubusercontent.com/u/14790466?v=4\" width=\"100px;\"/\u003e\u003cbr/\u003e\u003csub\u003e\u003cb\u003egreenkeeperio-bot\u003c/b\u003e\u003c/sub\u003e](https://github.com/greenkeeperio-bot)\u003cbr/\u003e|[\u003cimg src=\"https://avatars.githubusercontent.com/u/6897780?v=4\" width=\"100px;\"/\u003e\u003cbr/\u003e\u003csub\u003e\u003cb\u003ekillagu\u003c/b\u003e\u003c/sub\u003e](https://github.com/killagu)\u003cbr/\u003e|[\u003cimg src=\"https://avatars.githubusercontent.com/u/13450124?v=4\" width=\"100px;\"/\u003e\u003cbr/\u003e\u003csub\u003e\u003cb\u003eliuhanqu\u003c/b\u003e\u003c/sub\u003e](https://github.com/liuhanqu)\u003cbr/\u003e|\n| :---: | :---: | :---: | :---: | :---: | :---: |\n\n\nThis project follows the git-contributor [spec](https://github.com/xudafeng/git-contributor), auto updated at `Wed Oct 11 2023 10:27:33 GMT+0800`.\n\n\u003c!-- GITCONTRIBUTOR_END --\u003e\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnode-modules%2Fready-callback","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnode-modules%2Fready-callback","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnode-modules%2Fready-callback/lists"}