{"_id":"promise-make-counter","_rev":"2-965bf607c4b72e935f1e3dd2a6938a64","name":"promise-make-counter","dist-tags":{"latest":"1.0.2"},"versions":{"1.0.0":{"name":"promise-make-counter","version":"1.0.0","keywords":["promise","make","counter","reference"],"_id":"promise-make-counter@1.0.0","maintainers":[{"name":"fabiospampinato","email":"spampinabio@gmail.com"}],"homepage":"https://github.com/fabiospampinato/promise-make-counter#readme","bugs":{"url":"https://github.com/fabiospampinato/promise-make-counter/issues"},"dist":{"shasum":"dc2a54db1a4b211617cc9e18ebc2e02c3a6e34cf","tarball":"https://registry.npmjs.org/promise-make-counter/-/promise-make-counter-1.0.0.tgz","fileCount":12,"integrity":"sha512-L2tdYujNQiZStB6+u0RO9NgoObk6Qu53VvoSe+/pFwZ7gof8d9sqm6/+9bOEcunga5uecAXABGH0+g3z+pAPkg==","signatures":[{"sig":"MEUCIQCx1iwyCNsxZpVcmjZe5IWmL3lcz3Wj8llso8NAJUfcywIgVlj2ejTUeYe1V03+Tb5nAP4qAO5gHljUqhYtw2SUZVc=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":6132},"main":"dist/index.js","type":"module","types":"./dist/index.d.ts","exports":"./dist/index.js","gitHead":"a125d94e05365a7300dedf6e3f1d652a9425f0c0","scripts":{"test":"tsex test","clean":"tsex clean","compile":"tsex compile","test:watch":"tsex test --watch","compile:watch":"tsex compile --watch","prepublishOnly":"tsex prepare"},"_npmUser":{"name":"fabiospampinato","email":"spampinabio@gmail.com"},"repository":{"url":"git+https://github.com/fabiospampinato/promise-make-counter.git","type":"git"},"_npmVersion":"10.2.3","description":"A simple function that makes a counter-based promise, which can be incremented and decremented, and it resolves once its counter reaches zero.","directories":{},"_nodeVersion":"18.19.0","dependencies":{"promise-make-naked":"^2.1.2"},"_hasShrinkwrap":false,"devDependencies":{"fava":"^0.3.2","tsex":"^4.0.2","typescript":"^5.5.0-beta","promise-resolve-timeout":"^2.0.0"},"_npmOperationalInternal":{"tmp":"tmp/promise-make-counter_1.0.0_1716662992168_0.36852334247166185","host":"s3://npm-registry-packages"}},"1.0.1":{"name":"promise-make-counter","version":"1.0.1","keywords":["promise","make","counter","reference"],"_id":"promise-make-counter@1.0.1","homepage":"https://github.com/fabiospampinato/promise-make-counter#readme","bugs":{"url":"https://github.com/fabiospampinato/promise-make-counter/issues"},"dist":{"shasum":"468a077c39af8a1a38e65cded42b9059e4a0fa5c","tarball":"https://registry.npmjs.org/promise-make-counter/-/promise-make-counter-1.0.1.tgz","fileCount":12,"integrity":"sha512-R1JGFIgSJDpNV/JXxytAx6K79noEpcBiZXWDa3ic9WEMpBZbUdVVQjlA266SCicJ9CGqd70iGbbzbjRKbGU1Jg==","signatures":[{"sig":"MEYCIQD8Iy3dEPDcS1NluDmF1ocTUAiyoXbbg008rsjRynhKrgIhAN5QZsLxv3Dwhn0U3BofjcFhlc9e5sjgdMBFg14lDSCj","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":6050},"main":"dist/index.js","type":"module","types":"./dist/index.d.ts","exports":"./dist/index.js","gitHead":"ea6d9a68ca458f4d9e718cb3afada11f7fbb510d","scripts":{"test":"tsex test","clean":"tsex clean","compile":"tsex compile","test:watch":"tsex test --watch","compile:watch":"tsex compile --watch","prepublishOnly":"tsex prepare"},"_npmUser":{"name":"fabiospampinato","email":"spampinabio@gmail.com"},"repository":{"url":"git+https://github.com/fabiospampinato/promise-make-counter.git","type":"git"},"_npmVersion":"10.2.3","description":"A simple function that makes a counter-based promise, which can be incremented and decremented, and it resolves once its counter reaches zero.","directories":{},"_nodeVersion":"18.19.0","dependencies":{"promise-make-naked":"^3.0.0"},"_hasShrinkwrap":false,"devDependencies":{"fava":"^0.3.4","tsex":"^4.0.2","typescript":"^5.5.0-beta"},"_npmOperationalInternal":{"tmp":"tmp/promise-make-counter_1.0.1_1719764394633_0.11572344166378246","host":"s3://npm-registry-packages"}},"1.0.2":{"name":"promise-make-counter","repository":{"type":"git","url":"git+https://github.com/fabiospampinato/promise-make-counter.git"},"description":"A simple function that makes a counter-based promise, which can be incremented and decremented, and it resolves once its counter reaches zero.","license":"MIT","version":"1.0.2","type":"module","main":"dist/index.js","exports":"./dist/index.js","types":"./dist/index.d.ts","scripts":{"clean":"tsex clean","compile":"tsex compile","compile:watch":"tsex compile --watch","test":"tsex test","test:watch":"tsex test --watch","prepublishOnly":"tsex prepare"},"keywords":["promise","make","counter","reference"],"dependencies":{"promise-make-naked":"^3.0.2"},"devDependencies":{"fava":"^0.3.4","tsex":"^4.0.2","typescript":"^5.7.3"},"_id":"promise-make-counter@1.0.2","gitHead":"22fe39f34e575f29f51eaf45b5640c189074ab2f","bugs":{"url":"https://github.com/fabiospampinato/promise-make-counter/issues"},"homepage":"https://github.com/fabiospampinato/promise-make-counter#readme","_nodeVersion":"18.19.0","_npmVersion":"10.2.3","dist":{"integrity":"sha512-FJAxTBWQuQoAs4ZOYuKX1FHXxEgKLEzBxUvwr4RoOglkTpOjWuM+RXsK3M9q5lMa8kjqctUrhwYeZFT4ygsnag==","shasum":"0ca3b5995b66ba47e0535a7813e9f650b512df94","tarball":"https://registry.npmjs.org/promise-make-counter/-/promise-make-counter-1.0.2.tgz","fileCount":7,"unpackedSize":4217,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIE44e+EyIObYfmRd61m37CDCMDHGW6mZwk2zWiDRYwAzAiEAzyXgDoENz8LkPNOek9HQ7+qQyqNIx9yNPyk1w4j6S8A="}]},"_npmUser":{"name":"fabiospampinato","email":"spampinabio@gmail.com"},"directories":{},"maintainers":[{"name":"fabiospampinato","email":"spampinabio@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/promise-make-counter_1.0.2_1736633531906_0.0281926010844733"},"_hasShrinkwrap":false}},"time":{"created":"2024-05-25T18:49:52.167Z","modified":"2025-01-11T22:12:12.626Z","1.0.0":"2024-05-25T18:49:52.337Z","1.0.1":"2024-06-30T16:19:54.802Z","1.0.2":"2025-01-11T22:12:12.086Z"},"bugs":{"url":"https://github.com/fabiospampinato/promise-make-counter/issues"},"homepage":"https://github.com/fabiospampinato/promise-make-counter#readme","keywords":["promise","make","counter","reference"],"repository":{"type":"git","url":"git+https://github.com/fabiospampinato/promise-make-counter.git"},"description":"A simple function that makes a counter-based promise, which can be incremented and decremented, and it resolves once its counter reaches zero.","maintainers":[{"name":"fabiospampinato","email":"spampinabio@gmail.com"}],"readme":"# Promise Make Counter\n\nA simple function that makes a counter-based promise, which can be incremented and decremented, and it resolves once its counter reaches zero.\n\nThis is an alternative to creating a promise that waits on many other promises to resolve. You can do that, but creating many promises can be surprisingly slow, instead you could use this package, switch internally to using callbacks-style APIs rather than async/await-style APIs, and just increment the counter at the start of each callback, and decrement it at its end, once its job is done.\n\n## Install\n\n```sh\nnpm install --save promise-make-counter\n```\n\n## Usage\n\n```ts\nimport fs from 'node:fs';\nimport makeCounterPromise from 'promise-make-counter';\n\n// Let's create a counter-based promise\n\nconst {promise, isPending, increment, decrement} = makeCounterPromise ();\n\n// Now let's do some work that's tracked by our counter-based promise\n// It's important to always increment at the start, and decrement at the end\n\nfor ( const filePath of filePaths ) {\n\n  increment ();\n\n  fs.readFile ( filePath, 'utf8', ( error, data ) => {\n\n    decrement ();\n\n    // Actually do something here...\n\n  });\n\n}\n\n// Let's wait for the counter-based promise to resolve\n// This will happen once its internal counter will reach zero\n\nawait promise;\n```\n\n## License\n\nMIT © Fabio Spampinato\n","readmeFilename":"readme.md","license":"MIT"}