{"id":19987810,"url":"https://github.com/mawrkus/ah-context-store","last_synced_at":"2026-04-18T12:34:38.524Z","repository":{"id":42358002,"uuid":"157801461","full_name":"mawrkus/ah-context-store","owner":"mawrkus","description":"🔗  A context storage for async resources, based on the Node.js Async Hooks API","archived":false,"fork":false,"pushed_at":"2023-01-03T15:19:21.000Z","size":1330,"stargazers_count":0,"open_issues_count":15,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-08T21:40:51.866Z","etag":null,"topics":["async-hooks","async-resources","nodejs"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/mawrkus.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-11-16T02:30:30.000Z","updated_at":"2020-11-13T18:14:26.000Z","dependencies_parsed_at":"2023-02-01T07:00:55.825Z","dependency_job_id":null,"html_url":"https://github.com/mawrkus/ah-context-store","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mawrkus/ah-context-store","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mawrkus%2Fah-context-store","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mawrkus%2Fah-context-store/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mawrkus%2Fah-context-store/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mawrkus%2Fah-context-store/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mawrkus","download_url":"https://codeload.github.com/mawrkus/ah-context-store/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mawrkus%2Fah-context-store/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31969762,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-18T00:39:45.007Z","status":"online","status_checked_at":"2026-04-18T02:00:07.018Z","response_time":103,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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-hooks","async-resources","nodejs"],"created_at":"2024-11-13T04:38:40.584Z","updated_at":"2026-04-18T12:34:38.493Z","avatar_url":"https://github.com/mawrkus.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Async Context Store\n\nA context storage for async resources, based on the Node.js [Async Hooks API](https://nodejs.org/api/async_hooks.html).\n\n## 🔗 Installation (not yet published)\n\n```shell\n$ npm install ah-context-store // soon...\n```\n\n## 🔗 Usage\n\n## Example\n\n```javascript\nconst AsyncContextStore = require('async-context-store');\n\nconst asyncContextStore = new AsyncContextStore().enable();\n\nconst resolveAfter = ms =\u003e new Promise(resolve =\u003e setTimeout(resolve, ms));\n\nfunction handleRequest(requestId) {\n  return resolveAfter(10, `handle(${requestId})`)\n    .then(() =\u003e {\n      asyncContextStore.logStore();\n      assert.strictEqual(requestId, asyncContextStore.get('request.id'));\n    });\n}\n\n(async () =\u003e {\n  const request1P = resolveAfter(10, 'request1')\n    .then(() =\u003e {\n      asyncContextStore.set('request.id', 42).logStore();\n    })\n    .then(() =\u003e {\n      assert.strictEqual(42, asyncContextStore.get('request.id'));\n      return handleRequest(42);\n    });\n\n  const request2P = resolveAfter(10, 'request2')\n    .then(() =\u003e {\n      asyncContextStore.set('request.id', 69).logStore();\n    })\n    .then(() =\u003e {\n      assert.strictEqual(69, asyncContextStore.get('request.id'));\n      return handleRequest(69);\n    });\n\n  return Promise.all([request1P, request2P])\n    .then(() =\u003e {\n      assert.strictEqual(undefined, asyncContextStore.get('request.id'));\n      asyncContextStore.logStore().disable();\n    });\n})();\n```\n\n## API\n\n```javascript\nclass AsyncContextStore {\n  /**\n   * @param {String[]} [debug=[]] ['methods', 'hooks]\n   */\n  constructor({ debug } = { debug: [] }) {}\n\n  /**\n   * @return {Number} Number of contexts currently stored.\n   */\n  get size() {}\n\n  /**\n   * @return {Object}\n   */\n  get store() {}\n\n  /**\n   * @return {AsyncContextStore} this\n   */\n  enable() {}\n\n  /**\n   * @return {AsyncContextStore} this\n   */\n  disable() {}\n\n  /**\n   * @param {String} key\n   * @param {*} value\n   * @return {AsyncContextStore} this\n   */\n  set(key, value) {}\n\n  /**\n   * @param {String} key\n   * @return {*} value\n   */\n  get(key) {}\n\n  /**\n   * @param {...any} args\n   * @return {AsyncContextStore} this\n   */\n  log(...args) {}\n\n  /**\n   * @param {Number} [asyncId=this._asyncHooks.executionAsyncId()]\n   * @return {AsyncContextStore} this\n   */\n  logContext(asyncId = this._asyncHooks.executionAsyncId()) {}\n\n  /**\n   * @return {AsyncContextStore} this\n   */\n  logStore() {}\n```\n\n## 🔗 Demos\n\n- Promise-based demos.\n- `async-await` demos.\n- [Hapi v17](https://hapijs.com/api/17.7.0) demo, to illustrate HTTP request tracing across multiple services.\n\nClone the project...\n\n```shell\n$ git clone https://github.com/mawrkus/async-context-store.git\n$ cd async-context-store\n$ npm install\n\n$ npm run demo:async-await\n$ npm run demo:promises\n$ npm run demo:server\n\n$ ./demos/demo-server-stress.sh my-agent\n```\n\n## 🔗 Resources\n\n- \"Grokking Asynchronous Work in Node.js\" by Thorsten Lorenz:\n  + Video -\u003e https://www.youtube.com/watch?v=8Xoht4J6Jjw\n  + Slides -\u003e http://thlorenz.com/talks/async-hooks/book/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmawrkus%2Fah-context-store","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmawrkus%2Fah-context-store","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmawrkus%2Fah-context-store/lists"}