{"_id":"p-fifo","_rev":"1-51b851cc3422c451f88c3a839e59bb5d","name":"p-fifo","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"p-fifo","version":"1.0.0","description":"Promised First-In-First-Out buffer. Await on push to be told when a value is consumed and await on shift for a value to consume when the buffer is empty.","main":"index.js","scripts":{"test":"ava test.js --verbose","lint":"standard","coverage":"nyc --reporter=text --reporter=lcov npm test"},"keywords":["fifo","buffer","queue","promise","push","shift","array"],"author":{"name":"Alan Shaw"},"license":"MIT","dependencies":{"fast-fifo":"^1.0.0","p-defer":"^3.0.0"},"devDependencies":{"ava":"^2.2.0","nyc":"^14.1.1","standard":"^13.1.0"},"ava":{"babel":false,"compileEnhancements":false},"repository":{"type":"git","url":"git+https://github.com/alanshaw/p-fifo.git"},"bugs":{"url":"https://github.com/alanshaw/p-fifo/issues"},"homepage":"https://github.com/alanshaw/p-fifo#readme","gitHead":"a1d5bd029a7daad02182d6532fbc5a6a2c3caa13","_id":"p-fifo@1.0.0","_nodeVersion":"12.2.0","_npmVersion":"6.9.0","_npmUser":{"name":"alanshaw","email":"alan138@gmail.com"},"dist":{"integrity":"sha512-IjoCxXW48tqdtDFz6fqo5q1UfFVjjVZe8TC1QRflvNUJtNfCUhxOUw6MOVZhDPjqhSzc26xKdugsO17gmzd5+A==","shasum":"e29d5cf17c239ba87f51dde98c1d26a9cfe20a63","tarball":"https://registry.npmjs.org/p-fifo/-/p-fifo-1.0.0.tgz","fileCount":6,"unpackedSize":6807,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJdQZ3kCRA9TVsSAnZWagAAl1kP/1ccWQdCPM7tWVAHHNPZ\nGpAW5/Pdk5utZAndZIJzJlwlQZAWw2PuNQIw5BMcodSHJUW/HMw7MItwbhG2\nlKmVcp6BP2O8YD6qFUoaGn6fUUG1vCiCl3d7hEXV2a6up0OpK2o9NjjrEm2B\nGkkcj/B/7Cw03rV8PQQWDe4mctAP2iE9oN3/FauSun1VzjeSbxcWBY9AgvLZ\nnzEKKxm9uiO2aztrISEiovNGcG9w3CH29yqMHFvWuY23KkM4kFfCaWeDyJFW\ng0ZD6dOp8oxoefF8ehVOgEe92PzVlgJsb9y2OEtKQ4/ZXjFMz8hL/epyQGdA\nwGAvFtUEl6a8m47tbifM12hcv3x6I8XbIbDZ+GZPeO0vHKQ8EDHjocElml0y\nCCMf16xAEum1iMqG1bvf03wttZ8b2NvtKX3k+r0dqZNQz98la4TCJcWHNbrd\naSE7ylGPSzawQzLSUMY5bd5To1NVP8ZnxWxlRzzDj2qLuuqHndDmH/hcRbfs\nHamJYv99gZtHMR70Qg408K2R1+UQuZ7usf1AdzmM9XqugoogJF3ithrM3il2\nKZAQjaiM4sEnwA8GTn9yiXdzTZ/5OOv9sba4Rj0mgVcyy/RyojSEwadQyToG\nYZDxBL0jOuW+MchsZ90laUFMGmx/Jr6vH9ohkD14qQrGustxwlPKzHZoFfZf\nSmRo\r\n=zHFC\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIA7U5ycwZeJD+7KLVK9mTvr+vkujphLz5hKJXhRzsVSjAiApwNrKXYiEQBJD6Xmnk3wxLzpax0Hcq2uTNy2SeB1eQQ=="}]},"maintainers":[{"name":"alanshaw","email":"alan138@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/p-fifo_1.0.0_1564581347700_0.7020078385258748"},"_hasShrinkwrap":false}},"time":{"created":"2019-07-31T13:55:47.700Z","1.0.0":"2019-07-31T13:55:48.044Z","modified":"2022-05-12T10:29:06.946Z"},"maintainers":[{"name":"alanshaw","email":"alan138@gmail.com"}],"description":"Promised First-In-First-Out buffer. Await on push to be told when a value is consumed and await on shift for a value to consume when the buffer is empty.","homepage":"https://github.com/alanshaw/p-fifo#readme","keywords":["fifo","buffer","queue","promise","push","shift","array"],"repository":{"type":"git","url":"git+https://github.com/alanshaw/p-fifo.git"},"author":{"name":"Alan Shaw"},"bugs":{"url":"https://github.com/alanshaw/p-fifo/issues"},"license":"MIT","readme":"# p-fifo\n\n[![Build Status](https://travis-ci.org/alanshaw/p-fifo.svg?branch=master)](https://travis-ci.org/alanshaw/p-fifo)\n[![dependencies Status](https://david-dm.org/alanshaw/p-fifo/status.svg)](https://david-dm.org/alanshaw/p-fifo)\n[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)\n\n> Promised First-In-First-Out buffer. Await on push to be told when a value is consumed and await on shift for a value to consume when the buffer is empty\n\n## Install\n\n```sh\nnpm i p-fifo\n```\n\n## Usage\n\n### Await on push\n\n`await` on push to be told when your pushed value is consumed:\n\n```js\nconst Fifo = require('p-fifo')\nconst fifo = new Fifo()\n\n// Consume a value from the buffer after 1 second\nsetTimeout(() => fifo.shift(), 1000)\n\nconsole.time('push')\n// Nothing in the buffer, push a value and wait for it to be consumed\nawait fifo.push('hello')\nconsole.log('\"hello\" was consumed')\nconsole.timeEnd('push')\n\n// Output:\n// \"hello\" was consumed\n// push: 1006.723ms\n```\n\n### Await on shift\n\nIf the buffer is empty, you can `await` on a value to be pushed:\n\n```js\nconst Fifo = require('p-fifo')\nconst fifo = new Fifo()\n\n// Push a value into the buffer after 1 second\nsetTimeout(() => fifo.push('hello'), 1000)\n\nconsole.time('shift')\n// Nothing in the buffer, wait for something to arrive\nconst value = await fifo.shift()\nconsole.log(`consumed \"${value}\" from the buffer`)\nconsole.timeEnd('shift')\n\n// Output:\n// consumed \"hello\" from the buffer\n// shift: 1002.652ms\n```\n\n## API\n\n```js\nconst fifo = new Fifo()\n```\n\n### `fifo.push(value): Promise`\n\nAdd a value to the end of the FIFO buffer.\n\nReturns a promise that is resolved when the pushed value is shifted off the start of the buffer.\n\n### `fifo.shift(): Promise<Any>`\n\nRemove the first value from the FIFO buffer and return that removed value in a promise.\n\nReturns a promise that resolves to a value from start of the FIFO buffer. If there are no values in the buffer the promise will resolve when a value is next pushed.\n\nNote that multiple calls to shift when the buffer is empty will not resolve to the same value i.e. a corresponding number of calls to `push` will need to be made to resolve all the promises returned by calls to `shift`.\n\n### `fifo.isEmpty(): Boolean`\n\nReturns `true` if the FIFO buffer is empty and `false` otherwise.\n\n## Contribute\n\nFeel free to dive in! [Open an issue](https://github.com/alanshaw/p-fifo/issues/new) or submit PRs.\n\n## License\n\n[MIT](LICENSE) © Alan Shaw\n","readmeFilename":"README.md"}