{"name":"writable-consumable-stream","version":"1.1.1","keywords":["async","generator","stream","data","for-await-of"],"author":{"name":"Jonathan Gros-Dubois"},"license":"MIT","_id":"writable-consumable-stream@1.1.1","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":"f6046da5df15debb344dfa3ce3fcddd7f5ddfaff","tarball":"http://registry-npm.ywwl.com/writable-consumable-stream/download/writable-consumable-stream-1.1.1.tgz","fileCount":6,"integrity":"sha512-qARFG8dkQo2kX72UB2gnNwyCBS4x64lFjaJgRQnfbmrJVnfMpmYCUlqLD4kwmsFw6LcWo0Qv5MzkHET2L99ezw==","signatures":[{"sig":"MEQCIG8Xf6PPuWw5Hyrox66NuGs+pmI9D9PaTYd7EcpAn1pWAiA7rzcpHSH/dXmN4RAYnWJDFr99a7ur17UP/upcFTYIYQ==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":55667,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcbeKbCRA9TVsSAnZWagAAd6UP/0TK11gcusk4yt5pUmv+\nmzgxHr+/OT7VsUrt6GqV12tTxAXVFwEiLzmoi1Yps0Qn8nIR0J7+Chq1Y8a7\nsZu4VGdCVsN+qYCIyDXYEhfimaUoCPCoxwNDCp2/70QUM0idsebNUFfcnylk\nCf2NEA04F+pYpGfRj4mARyHtiCjRf2OsgcVzNgCr8pT3weypcaA5UPLYv21j\nxXhP6kyeQVaNOlqEyL+sX0xP7+f5Ktouf5FBMU/l7mdmnXkYoMzLpBf9W2H6\nVI5A9xJ9iAhjh4zOSFf7gOAosQib3lyLMw9VMB5MpSjzhOVMdorIh4Y+3zsi\nHlaxdYpj/V2Q6M8OsZYJTCxt5RcUQauMSts9tnjURlTdztsnAb0FBnqOrxtV\n1xgmYUDP6JNY+ONbTI6OyqnI/E7VEfkkH8YLExgLq9BCOqs6i8Jl2UANTLle\nYHguN8+VtpPr19pj+Z+RQ3jepBNDk7cIPAr6kL2tq15KqPCWxajWQwBCpEKh\n694nHUf5ZdtW516gvvqiBboFOlp6w+g2wu+tmVYINt5MfIM4ri0iOO666ypm\n3XjK25EaK8/RQ1rKjJbDjqfkww51eOS86jZwh3T+fLH8zTr4YS7JbczexCXP\nBM+G46bboHQnGEVF9RVmGnjQ68K7B3lCj3BIARI0t+XewRPoYNlZeoxLmZUW\nrriu\r\n=69CL\r\n-----END PGP SIGNATURE-----\r\n","size":7309,"noattachment":false,"key":"/writable-consumable-stream/-/writable-consumable-stream-1.1.1.tgz"},"main":"index.js","gitHead":"9fd7f6b07218f2de83f9e15d5378deb58dc24b2a","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":"5.6.0","description":"An async stream which can be iterated over using a for-await-of loop.","directories":{},"_nodeVersion":"10.0.0","dependencies":{"consumable-stream":"^1.0.0"},"_hasShrinkwrap":false,"devDependencies":{"mocha":"^5.2.0"},"_npmOperationalInternal":{"tmp":"tmp/writable-consumable-stream_1.1.1_1550705306515_0.7974998407329439","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":1550705306725,"_cnpm_publish_time":1550705306725,"dist-tags":{"latest":"5.0.1"}}