{"name":"writable-consumable-stream","version":"2.0.0","keywords":["async","generator","stream","data","for-await-of"],"author":{"name":"Jonathan Gros-Dubois"},"license":"MIT","_id":"writable-consumable-stream@2.0.0","maintainers":[{"name":"topcloudsystems","email":"grosjona@yahoo.com.au"}],"homepage":"https://github.com/SocketCluster/writable-consumable-stream#readme","bugs":{"url":"https://github.com/SocketCluster/writable-consumable-stream/issues"},"dist":{"shasum":"102beeea0b20b4862f263dd8688c926a4caa28d3","tarball":"http://registry-npm.ywwl.com/writable-consumable-stream/download/writable-consumable-stream-2.0.0.tgz","fileCount":6,"integrity":"sha512-SITambzxtPTFU/wR82h+zOKGBiEv5V8gC1mt8xvoE1/168ApEa8H+6s2UToYJo3VLL7sNYTaApKuPD+pZHMGJQ==","signatures":[{"sig":"MEUCIQCdZjq2g55jByUK8iWQwedCPiAFaqdlerfNJjPmUKwOwQIgeAysK+pK8i66AuSGYM2CTkLq9k6+5BcHm2Lcqp6lNbM=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":55374,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJePaUYCRA9TVsSAnZWagAA3hgP+QEXen3FDOOh3wA2+oaX\nCoCyIcY+pfD8Z3oBiWZtmRFul2E+6jLApimqBf1yWiHjIgzIYYpL9uE5CLx/\ndwqafMI5vkCXG3cfjajTxEk6W0awo0Ct1iVE63/1NwjedGlfDLv4/+opV5iR\n8wUk17a9a/ImMHK0oauRvTyVZsgWLa5wXYaDCVfym1bZsI/CIxOsNmrARdhE\nn8LWqgrYtBm0B6NZ0H8JOb0kDaJGpNLv3+bKTigvDouyQDaS6sbeuq2bSxyA\nvzD0mUnbzIIEYT1FOfUOeNPc4bEtx33wrLdhL48Olvfbb2zTEXSrKm3zlhbN\nIkE1Uu2cb3ddvoSMmFMlxnO/4D0I7FN9yYHj1AFul+QG20xjBT2VF1tPlkXs\nUBDiKqnniZuR7GgF21nzPX37mRvbrAiAjR11+nEVyrVu4O015uoKf0cqMuQ0\nyTCC7aIP8BA6/+wlduIet/b0aN9pTxdUlZ2fI6BhLNolUhjH8kGWwxfITZqD\n1SsNDQLX1ajW3ZpojR3vl0e7MI9vlu7CdRAOrI2oSqTG5brRlg5ds0XBTjHR\nuXnvnxPh+f3aQcBN1AH9gETdSuEwymwHa3b1GmeoWlUSeoSEMIhfQ7476uBL\nmoWRhleeJNE6SKgF5yDDDRhEbsXaW9+UZcHJkfsSvWt6qzvI69rQH6d+7bQ8\n71sC\r\n=iet+\r\n-----END PGP SIGNATURE-----\r\n","size":7300,"noattachment":false,"key":"/writable-consumable-stream/-/writable-consumable-stream-2.0.0.tgz"},"main":"index.js","gitHead":"4ee99fc37fedbe861f0686fa2cb77bea94b62a4c","scripts":{"test":"./node_modules/mocha/bin/_mocha --reporter spec --timeout 10000 --slow 10000"},"_npmUser":{"name":"topcloudsystems","email":"grosjona@yahoo.com.au"},"repository":{"url":"git+ssh://git@github.com/SocketCluster/writable-consumable-stream.git","type":"git"},"_npmVersion":"6.7.0","description":"An async stream which can be iterated over using a for-await-of loop.","directories":{},"_nodeVersion":"11.13.0","dependencies":{"consumable-stream":"^2.0.0"},"_hasShrinkwrap":false,"devDependencies":{"mocha":"^5.2.0"},"_npmOperationalInternal":{"tmp":"tmp/writable-consumable-stream_2.0.0_1581098264233_0.6291062468282578","host":"s3://npm-registry-packages"},"readme":"# writable-consumable-stream\nAn async stream which can be iterated over using a for-await-of loop and which can be written to.\n\nThe `WritableConsumableStream` class extends the `ConsumableStream` class.  \nSee https://github.com/SocketCluster/consumable-stream\n\n## Installation\n\n```\nnpm install writable-consumable-stream\n```\n\n## Usage\n\n### Require\n\n```js\nconst WritableConsumableStream = require('writable-consumable-stream');\n```\n\n### Consume a stream and write to it asynchronously:\n\n```js\nlet consumableStream = new WritableConsumableStream();\n\nasync function consumeAsyncIterable(asyncIterable) {\n  // Consume iterable data asynchronously.\n  for await (let packet of asyncIterable) {\n    console.log('Packet:', packet);\n  }\n}\nconsumeAsyncIterable(consumableStream);\n\nsetInterval(() => {\n  // Write data to the stream asynchronously,\n  consumableStream.write(`Timestamp: ${Date.now()}`);\n}, 100);\n```\n\n### Consume a stream using a while loop:\n\n```js\nlet consumableStream = new WritableConsumableStream();\n\nasync function consumeAsyncIterable(asyncIterable) {\n  // Consume iterable data asynchronously.\n  // Works in older environments.\n  let asyncIterator = asyncIterable.createConsumer();\n  while (true) {\n    let packet = await asyncIterator.next();\n    if (packet.done) break;\n    console.log('Packet:', packet.value);\n  }\n}\nconsumeAsyncIterable(consumableStream);\n\nsetInterval(() => {\n  // Write data to the stream asynchronously,\n  consumableStream.write(`Timestamp: ${Date.now()}`);\n}, 100);\n```\n\n### Consume a filtered stream using an async generator:\n\n```js\nlet consumableStream = new WritableConsumableStream();\n\n// Creates an async generator which only produces packets which are allowed by the\n// specified filterFunction.\nasync function* createFilteredStreamGenerator(fullStream, filterFunction) {\n  for await (let packet of fullStream) {\n    if (filterFunction(packet)) {\n      yield packet;\n    }\n  }\n}\n\nasync function consumeAsyncIterable(asyncIterable) {\n  // Consume iterable data asynchronously.\n  for await (let packet of asyncIterable) {\n    console.log('Packet:', packet);\n  }\n}\n\n// The filter function will only include strings which end with the number 5.\nfunction filterFn(data) {\n  return /5$/.test(data);\n}\nlet filteredStreamGenerator = createFilteredStreamGenerator(consumableStream, filterFn);\n\nconsumeAsyncIterable(filteredStreamGenerator);\n\nsetInterval(() => {\n  // Write data to the stream asynchronously,\n  consumableStream.write(`Timestamp: ${Date.now()}`);\n}, 100);\n```\n\n### Consume only the next data object which will be written to the stream:\n\n```js\nlet consumableStream = new WritableConsumableStream();\n\n(async () => {\n  let data = await consumableStream.once();\n  console.log(data);\n})();\n\nsetInterval(() => {\n  // Write data to the stream asynchronously,\n  consumableStream.write(`Timestamp: ${Date.now()}`);\n}, 100);\n```\n\n### Releasing a consumer\n\nKilling or closing a consumer removes it from the stream but does not discard the\npackets which it has not consumed yet - this is what allows a consumer to resume\nlater without missing any messages. For as long as a consumer is still reachable,\nthose packets, and everything written to the stream afterwards, stay in memory.\n\nSo once you are finished with a consumer, `break` out of its `for await...of` loop,\nor kill it with `stream.killConsumer(consumer.id)` (or `stream.kill()` for all\nconsumers) and discard any remaining references to it.\n\nSee `test/` directory for additional examples.\n","publish_time":1581098264328,"_cnpm_publish_time":1581098264328,"dist-tags":{"latest":"5.0.1"}}