{"id":13847379,"url":"https://github.com/gms1/node-async-context","last_synced_at":"2025-07-12T09:31:48.160Z","repository":{"id":14831353,"uuid":"77180833","full_name":"gms1/node-async-context","owner":"gms1","description":"a continuation local storage / asynchronous execution context for node.js  via async_hooks","archived":true,"fork":false,"pushed_at":"2023-11-19T15:52:40.000Z","size":1360,"stargazers_count":71,"open_issues_count":1,"forks_count":5,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-08-04T18:02:32.604Z","etag":null,"topics":["async-hooks","asynchronouse-execution-context","cls","continuation-local-storage","javascript","nodejs","typescript"],"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/gms1.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}},"created_at":"2016-12-22T22:46:52.000Z","updated_at":"2023-11-19T15:53:41.000Z","dependencies_parsed_at":"2023-11-19T16:47:33.285Z","dependency_job_id":null,"html_url":"https://github.com/gms1/node-async-context","commit_stats":{"total_commits":240,"total_committers":8,"mean_commits":30.0,"dds":"0.37916666666666665","last_synced_commit":"ae0f09aeac9cec07e6b9cfda59cddd171cbbee19"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gms1%2Fnode-async-context","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gms1%2Fnode-async-context/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gms1%2Fnode-async-context/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gms1%2Fnode-async-context/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gms1","download_url":"https://codeload.github.com/gms1/node-async-context/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225812883,"owners_count":17528081,"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":["async-hooks","asynchronouse-execution-context","cls","continuation-local-storage","javascript","nodejs","typescript"],"created_at":"2024-08-04T18:01:18.455Z","updated_at":"2024-11-21T22:30:19.096Z","avatar_url":"https://github.com/gms1.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# node-async-context (asyncctx)\n\n**THIS PROJECT HAS BEEN MOVED!**\n\n**THE NEW LOCATION IS HERE: [asyncctx](https://github.com/gms1/HomeOfThings/tree/master/packages/node/asyncctx)**\n\n\n[![npm version](https://badge.fury.io/js/asyncctx.svg)](https://badge.fury.io/js/asyncctx)\n[![Build Workflow](https://github.com/gms1/node-async-context/actions/workflows/build.yml/badge.svg?branch=master)](https://github.com/gms1/node-async-context/actions/workflows/build.yml)\n[![Coverage Status](https://codecov.io/gh/gms1/node-async-context/branch/master/graph/badge.svg)](https://codecov.io/gh/gms1/node-async-context)\n[![Dependency Status](https://david-dm.org/gms1/node-async-context.svg)](https://david-dm.org/gms1/node-async-context)\n[![Known Vulnerabilities](https://snyk.io/test/github/gms1/node-async-context/badge.svg)](https://snyk.io/test/github/gms1/node-async-context)\n\n![NPM](https://img.shields.io/npm/l/asyncctx)\n\nThis module allows you to create an asynchronous execution context for JavaScript or TypeScript\n\n\u003e NOTE: This module is based on [async_hooks](https://github.com/nodejs/node/blob/master/doc/api/async_hooks.md) an experimental built-in node.js module introduced in v8.0.0\n\n## Deprecation\n\u003c!-- --\u003e\n\u003e NOTE: This module is now deprecated in favour of [AsyncLocalStorage](https://nodejs.org/api/async_context.html#async_context_new_asynclocalstorage)\n\u003e which is available for nodejs \u003e= 12\n\n### quick start using AsyncLocalStorage\n\n```Typescript\n class ContinuationLocalStorage\u003cT\u003e extends AsyncLocalStorage\u003cT\u003e {\n   public getContext(): T | undefined {\n      return this.getStore();\n    }\n    public setContext(value: T): T {\n      this.enterWith(value);\n      return value;\n    }\n  }\n```\n\n## Introduction\n\nTo give you an idea of how **asyncctx** is supposed to be used:\n\n```TypeScript\nimport { ContinuationLocalStorage } from 'asyncctx';\n\nclass MyLocalStorage {\n  value: number;\n}\n\nlet cls = new ContinuationLocalStorage\u003cMyLocalStorage\u003e();\ncls.setRootContext({ value: 1});\n\nprocess.nextTick(() =\u003e {\n  let curr1 = cls.getContext(); // value is 1\n  cls.setContext({ value: 2});  // value should be 2 in the current execution context and below\n  process.nextTick(() =\u003e {\n    let curr2 = cls.getContext(); // value is 2\n    cls.setContext({ value: 3});  // value should be 3 in the current execution context and below\n    process.nextTick(() =\u003e {\n      let curr3 = cls.getContext(); // value is 3\n    });\n  });\n  process.nextTick(() =\u003e {\n    let curr4 = cls.getContext(); // value is 2\n  });\n});\n```\n\n## License\n\n**node-async-context (asyncctx)** is licensed under the MIT License:\n[LICENSE](./LICENSE)\n\n## Release Notes\n\n| Release   | Notes                                                                                   |\n|-----------|-----------------------------------------------------------------------------------------|\n| 2.0.18-19 | deprecated in favour of AsyncLocalStorage                                               |\n| 2.0.12-17 | maintenance release, nodejs 14 support                                                  |\n| 2.0.11    | #54: fixed memory leak for chaining asynchronous calls infinitely; thanks to Reko Tiira |\n| 2.0.10    | maintenance release                                                                     |\n| 2.0.9     | node 13 supported                                                                       |\n| 2.0.3-8   | maintenance release                                                                     |\n| 2.0.2     | #47: fixed loosing context for unknown resource types; thanks to Pasi Tuominen          |\n| 2.0.1     | maintenance release                                                                     |\n| 2.0.0     | targeting es2015; dropped support for nodejs \u003c v8                                       |\n|           | please use asyncctx@\u003c2.0 for nodejs v4 - v11 support                                    |\n| 1.1.0     | fixed support for nodes \u003c v8                                                            |\n| 1.0.5-10  | maintenance release                                                                     |\n| 1.0.4     | node 10 supported                                                                       |\n| 1.0.3     | node 9 supported                                                                        |\n| 1.0.2     | maintenance release                                                                     |\n| 1.0.1     | added support for older nodejs versions (4,6,7) using internal copy of async-hook@1.7.1 |\n| 1.0.0     | is now based on 'async_hooks' (a built-in nodejs v8.0 module)                           |\n| 0.0.6     | maintenance releases                                                                    |\n| 0.0.5     | async-hook 1.7.1                                                                        |\n| 0.0.1-4   | initial version                                                                         |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgms1%2Fnode-async-context","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgms1%2Fnode-async-context","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgms1%2Fnode-async-context/lists"}