{"id":21531923,"url":"https://github.com/matrixai/js-async-init","last_synced_at":"2025-03-17T19:28:13.720Z","repository":{"id":36968730,"uuid":"411619970","full_name":"MatrixAI/js-async-init","owner":"MatrixAI","description":"Asynchronous initialization and deinitialization decorators for JavaScript/TypeScript applications","archived":false,"fork":false,"pushed_at":"2025-02-04T01:27:53.000Z","size":878,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":5,"default_branch":"staging","last_synced_at":"2025-03-07T06:05:46.831Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://polykey.com","language":"TypeScript","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/MatrixAI.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-09-29T09:59:02.000Z","updated_at":"2025-02-04T01:24:26.000Z","dependencies_parsed_at":"2024-05-14T10:51:03.686Z","dependency_job_id":"a64dfae7-dff9-47f0-8452-8450aeb09258","html_url":"https://github.com/MatrixAI/js-async-init","commit_stats":{"total_commits":65,"total_committers":5,"mean_commits":13.0,"dds":"0.16923076923076918","last_synced_commit":"99a60d1dd914676ddef06bb7f39c1f5c8435e0c8"},"previous_names":[],"tags_count":28,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MatrixAI%2Fjs-async-init","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MatrixAI%2Fjs-async-init/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MatrixAI%2Fjs-async-init/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MatrixAI%2Fjs-async-init/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MatrixAI","download_url":"https://codeload.github.com/MatrixAI/js-async-init/tar.gz/refs/heads/staging","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244096070,"owners_count":20397332,"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-24T02:18:11.738Z","updated_at":"2025-03-17T19:28:13.691Z","avatar_url":"https://github.com/MatrixAI.png","language":"TypeScript","readme":"# js-async-init\n\nAsynchronous initialization and deinitialization decorators for JavaScript/TypeScript applications.\n\nBecause decorators are experimental, you must enable: `\"experimentalDecorators\": true` in your `tsconfig.json` to use this library.\n\nTypeScript does not allow decorator properties that are protected or private.\n\nExample Usage:\n\n```ts\nimport { CreateDestroyStartStop, ready } from '@matrixai/async-init/dist/CreateDestroyStartStop';\n\n// this hack is necessary to ensure that X's type is decorated\ninterface X extends CreateDestroyStartStop {};\n@CreateDestroyStartStop(new Error('Running'), new Error('Destroyed'))\nclass X {\n  protected y: Y;\n\n  public static async createX(\n    {\n      y\n    }: {\n      y?: Y\n    } = {}\n  ) {\n    y = y ?? await Y.createY();\n    const x = new this({ y });\n    await x.start();\n    return x;\n  }\n\n  public constructor ({ y }: { y: Y }) {\n    this.y = y;\n  }\n\n  public async start(): Promise\u003cvoid\u003e {\n    await this.y.start();\n    console.log('X started');\n  }\n\n  public async stop(): Promise\u003cvoid\u003e {\n    await this.y.stop();\n    console.log('X stopped');\n  }\n\n  public async destroy(): Promise\u003cvoid\u003e {\n    await this.y.destroy();\n    console.log('X destroyed');\n  }\n\n  @ready(new Error('Not Running'))\n  public async doSomething() {\n    await this.y.doSomething();\n    console.log('X did something');\n  }\n}\n\n// this hack is necessary to ensure that Y's type is decorated\ninterface Y extends CreateDestroyStartStop {};\n@CreateDestroyStartStop(new Error('Running'), new Error('Destroyed'))\nclass Y {\n  public static async createY() {\n    return new this();\n  }\n\n  public constructor () {\n  }\n\n  public async destroy(): Promise\u003cvoid\u003e {\n    console.log('Y destroyed');\n  }\n\n  @ready(new Error('Not Running'))\n  public async doSomething(): Promise\u003cvoid\u003e {\n    console.log('Y did something');\n  }\n}\n\nasync function main () {\n  const x = await X.createX();\n  await x.doSomething();\n  await x.stop();\n  await x.destroy();\n  console.log(x);\n}\n\nmain();\n```\n\nThe `start`, `stop`, and `destroy` calls are all concurrent-controlled with `RWLockWriter`. They are idempotent and they are mutually exclusive between each other and any blocking `ready` decorated methods. Decorated methods can block `start`, `stop`, and `destroy`, but share a read lock between each other.\n\nRefer to https://gist.github.com/CMCDragonkai/1dbf5069d9efc11585c27cc774271584 for further the motivation of this library.\n\n## Installation\n\n```sh\nnpm install --save @matrixai/async-init\n```\n\n## Development\n\nRun `nix develop`, and once you're inside, you can use:\n\n```sh\n# install (or reinstall packages from package.json)\nnpm install\n# build the dist\nnpm run build\n# run the repl (this allows you to import from ./src)\nnpm run tsx\n# run the tests\nnpm run test\n# lint the source code\nnpm run lint\n# automatically fix the source\nnpm run lintfix\n```\n\n### Docs Generation\n\n```sh\nnpm run docs\n```\n\nSee the docs at: https://matrixai.github.io/js-async-init/\n\n### Publishing\n\nPublishing is handled automatically by the staging pipeline.\n\nPrerelease:\n\n```sh\n# npm login\nnpm version prepatch --preid alpha # premajor/preminor/prepatch\ngit push --follow-tags\n```\n\nRelease:\n\n```sh\n# npm login\nnpm version patch # major/minor/patch\ngit push --follow-tags\n```\n\nManually:\n\n```sh\n# npm login\nnpm version patch # major/minor/patch\nnpm run build\nnpm publish --access public\ngit push\ngit push --tags\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatrixai%2Fjs-async-init","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmatrixai%2Fjs-async-init","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatrixai%2Fjs-async-init/lists"}