{"_id":"@cameronhunter/pending-promises","_rev":"1-a46bf6d30e87613c97fd02bc747c8eba","name":"@cameronhunter/pending-promises","dist-tags":{"latest":"1.0.1"},"versions":{"1.0.0":{"name":"@cameronhunter/pending-promises","version":"1.0.0","description":"A map of pending promises that can be resolved/rejected at a later time","main":"./build/index.js","types":"./build/index.d.ts","keywords":["promise","event handlers"],"author":{"name":"Cameron Hunter","email":"hello@cameronhunter.co.uk"},"license":"MIT","devDependencies":{"@changesets/cli":"^2.26.2","@tsconfig/node-lts":"^18.12.5","@types/debug":"^4.1.12","@types/jest":"^29.5.8","@types/node":"^18","jest":"^29.7.0","prettier":"^3.1.0","prettier-2":"npm:prettier@^2","ts-jest":"^29.1.1","typescript":"5.2.2"},"dependencies":{"@cameronhunter/async-with-timeout":"^3.1.0","@cameronhunter/clone-error":"^1.0.2","core-js":"^3.33.2","debug":"^4.3.4"},"publishConfig":{"access":"public"},"packageManager":"pnpm@8.10.5","scripts":{"build":"tsc -p ./tsconfig.build.json","format":"prettier --write .","test":"jest"},"_id":"@cameronhunter/pending-promises@1.0.0","_integrity":"sha512-UBBU8rPkbKHSH95ynXfo2Z+1+4vCwIRBvSS/2nsmbu8IMfPwdPuxwPANaonoQSkKIMXOv9+y1FxJ++QPsYoLPA==","_resolved":"/private/var/folders/gx/7m27h5097pz_71h88_57tw8m0000gn/T/06a6122f70f1a1d824726c9095395369/cameronhunter-pending-promises-1.0.0.tgz","_from":"file:cameronhunter-pending-promises-1.0.0.tgz","_nodeVersion":"18.15.0","_npmVersion":"9.5.0","dist":{"integrity":"sha512-UBBU8rPkbKHSH95ynXfo2Z+1+4vCwIRBvSS/2nsmbu8IMfPwdPuxwPANaonoQSkKIMXOv9+y1FxJ++QPsYoLPA==","shasum":"29449a4be7ae47a6fb4b8ee9f966902a12b1b79f","tarball":"https://registry.npmjs.org/@cameronhunter/pending-promises/-/pending-promises-1.0.0.tgz","fileCount":14,"unpackedSize":10915,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCtpDibgPjhOf/85l8GuEYDD+1gfiWoMjPEPw1tzD0EYAIgLbaur8CI6U1uKLCm9+baMDS9Z1M8u6++cdiFCegN3+I="}]},"_npmUser":{"name":"cameronhunter","email":"hello@cameronhunter.co.uk"},"directories":{},"maintainers":[{"name":"cameronhunter","email":"hello@cameronhunter.co.uk"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/pending-promises_1.0.0_1700353210845_0.25307048897944306"},"_hasShrinkwrap":false},"1.0.1":{"name":"@cameronhunter/pending-promises","version":"1.0.1","description":"A map of pending promises that can be resolved/rejected at a later time","main":"./build/index.js","types":"./build/index.d.ts","keywords":["promise","event handlers"],"repository":{"type":"git","url":"git+https://github.com/cameronhunter/pending-promises.git"},"author":{"name":"Cameron Hunter","email":"hello@cameronhunter.co.uk"},"license":"MIT","devDependencies":{"@changesets/cli":"^2.26.2","@tsconfig/node-lts":"^18.12.5","@types/debug":"^4.1.12","@types/jest":"^29.5.8","@types/node":"^20","jest":"^29.7.0","prettier":"^3.1.0","prettier-2":"npm:prettier@^2","ts-jest":"^29.1.1","typescript":"5.3.2"},"dependencies":{"@cameronhunter/async-with-timeout":"^3.1.0","@cameronhunter/clone-error":"^1.0.3","core-js":"^3.33.3","debug":"^4.3.4"},"publishConfig":{"access":"public"},"packageManager":"pnpm@8.10.5","scripts":{"build":"tsc -p ./tsconfig.build.json","format":"prettier --write .","test":"jest","release":"pnpm run build && pnpm run publish:github && pnpm run publish:npm","publish:github":"npm_config_registry=https://npm.pkg.github.com/ pnpm changeset publish","publish:npm":"npm_config_registry=https://registry.npmjs.org/ pnpm changeset publish"},"bugs":{"url":"https://github.com/cameronhunter/pending-promises/issues"},"homepage":"https://github.com/cameronhunter/pending-promises#readme","_id":"@cameronhunter/pending-promises@1.0.1","_integrity":"sha512-YklNEDg5/JGspxVTpKZr9oWop8m3FOuOTjej/zlmczEFez3ak4WyGOSOEiFDlcpOknOqvbf1OaB5J+SFANXabw==","_resolved":"/tmp/308b969ccb87e79fd721acb800335aa6/cameronhunter-pending-promises-1.0.1.tgz","_from":"file:cameronhunter-pending-promises-1.0.1.tgz","_nodeVersion":"20.9.0","_npmVersion":"10.1.0","dist":{"integrity":"sha512-YklNEDg5/JGspxVTpKZr9oWop8m3FOuOTjej/zlmczEFez3ak4WyGOSOEiFDlcpOknOqvbf1OaB5J+SFANXabw==","shasum":"ecf95df01f34deecaa446328993430ce804167ad","tarball":"https://registry.npmjs.org/@cameronhunter/pending-promises/-/pending-promises-1.0.1.tgz","fileCount":14,"unpackedSize":11042,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDot/wTMxaj5/4XqB4JVYPpX2yOz83DPZ20tIHgVLyStgIgKHWdjMsFjQeFv9kWDXe4AMzD00ZrqjxXv+OiP4EdQRQ="}]},"_npmUser":{"name":"cameronhunter","email":"hello@cameronhunter.co.uk"},"directories":{},"maintainers":[{"name":"cameronhunter","email":"hello@cameronhunter.co.uk"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/pending-promises_1.0.1_1700516818829_0.6108913817909356"},"_hasShrinkwrap":false}},"time":{"created":"2023-11-19T00:20:10.777Z","1.0.0":"2023-11-19T00:20:11.001Z","modified":"2023-11-20T21:46:59.229Z","1.0.1":"2023-11-20T21:46:59.029Z"},"maintainers":[{"name":"cameronhunter","email":"hello@cameronhunter.co.uk"}],"description":"A map of pending promises that can be resolved/rejected at a later time","keywords":["promise","event handlers"],"author":{"name":"Cameron Hunter","email":"hello@cameronhunter.co.uk"},"license":"MIT","readme":"# `@cameronhunter/pending-promises`\n\n[![npm package](https://img.shields.io/npm/v/%40cameronhunter/pending-promises?logo=npm)](https://www.npmjs.com/package/@cameronhunter/pending-promises)\n[![main branch status](https://img.shields.io/github/actions/workflow/status/cameronhunter/pending-promises/post-merge.yml?logo=github&label=main)](https://github.com/cameronhunter/pending-promises/actions/workflows/post-merge.yml)\n\n> A map of pending promises that can be resolved/rejected at a later time.\n\nThis data structure helps convert event-based APIs to promise-based. Here's an\nexample that wraps a WebSocket client, providing a promise-based API.\n\n```ts\nimport { PendingPromises } from '@cameronhunter/pending-promises';\n\nclass MyAPI {\n    readonly #responses: PendingPromises = new PendingPromises();\n    readonly #ws: WebSocket;\n\n    constructor(ws: WebSocket) {\n        this.#ws = ws;\n        this.#ws.on('message', this.#onMessage.bind(this));\n    }\n\n    send(message: string): Promise<string> {\n        // Create a new pending promise\n        const [id, promise] = this.#responses.create<string>();\n\n        ws.send(JSON.stringify({ id, message }), (err) => {\n            if (err) {\n                // Reject immediately if sending fails.\n                this.#responses.reject(id, err);\n            }\n        });\n\n        return promise;\n    }\n\n    #onMessage(event: WebSocket.MessageEvent): void {\n        const { id, result, error } = JSON.parse(event.data as string);\n\n        if (id) {\n            if (error) {\n                this.#responses.reject(id, error);\n            } else {\n                this.#responses.resolve(id, result);\n            }\n        }\n    }\n}\n```\n","readmeFilename":"README.md","homepage":"https://github.com/cameronhunter/pending-promises#readme","repository":{"type":"git","url":"git+https://github.com/cameronhunter/pending-promises.git"},"bugs":{"url":"https://github.com/cameronhunter/pending-promises/issues"}}