{"_id":"async-channel","_rev":"8-4a844b4d7a2c1e20a75d612e8cd5594f","name":"async-channel","description":"Send asynchronous values across concurrent lines of execution","dist-tags":{"latest":"0.2.0"},"versions":{"0.0.0":{"name":"async-channel","version":"0.0.0","description":"asynchronous channel","main":"index.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"author":{"name":"Johannes Goetz","email":"jgoetz01@gmail.com"},"license":"ISC","_id":"async-channel@0.0.0","_shasum":"7fc4b8a6bcd8bd9838b1ba4f3cd52d73b9c7fcb9","_from":".","_npmVersion":"1.4.9","_npmUser":{"name":"jgoetz","email":"jgoetz01@gmail.com"},"maintainers":[{"name":"jgoetz","email":"jgoetz01@gmail.com"}],"dist":{"shasum":"7fc4b8a6bcd8bd9838b1ba4f3cd52d73b9c7fcb9","tarball":"https://registry.npmjs.org/async-channel/-/async-channel-0.0.0.tgz","integrity":"sha512-l965gzYzq5lFZGPmsYoIAz4TcPfQZXNZOdvO9l2/RUMv9LR74ou12AP31QaRTfDIh3vRKmB9zejps0a6W6RYCA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIHjj+xTwnPi5YFurUk5tJoxaamU8lQYcmOkhaVj8rdDsAiBPQpmKraxXXIVgGg5sGcA19vp82MI6Wrr/mojYx/6ZLg=="}]},"directories":{}},"0.1.0":{"name":"async-channel","version":"0.1.0","description":"Send asynchronous values across concurrent lines of execution","license":"ISC","repository":{"type":"git","url":"git+https://github.com/kyle1320/async-channel.git"},"author":{"name":"Kyle Cutler"},"main":"lib/index.js","types":"lib/index.d.ts","scripts":{"build":"tsc","test":"jest --env=node --colors --coverage test","lint":"eslint --ext .js,.ts .","docs":"typedoc src/index.ts"},"devDependencies":{"@typescript-eslint/eslint-plugin":"^4.11.1","@typescript-eslint/parser":"^4.11.1","eslint":"^7.17.0","eslint-config-prettier":"^7.1.0","eslint-plugin-prettier":"^3.3.0","jest":"^26.6.3","prettier":"^2.2.1","ts-jest":"^26.4.4","typedoc":"^0.20.13","typescript":"^4.1.3"},"keywords":["channel","coroutine","concurrent","async","await","promise","communication","parallel"],"gitHead":"f57dc12392e1fb975e619c2f0dd0fb49fc91bacc","bugs":{"url":"https://github.com/kyle1320/async-channel/issues"},"homepage":"https://github.com/kyle1320/async-channel#readme","_id":"async-channel@0.1.0","_nodeVersion":"12.20.0","_npmVersion":"6.14.8","dist":{"integrity":"sha512-29/Z7fBBi7+0EhsHqTArey1i7vJILr7c8vvo/kltxU5vEyrcePGPtXqaFunJ0llcKSNbO+lPtaf8yYzvxMU/rw==","shasum":"ae63dca6aba622e18ec0a65379ca18340ecfc140","tarball":"https://registry.npmjs.org/async-channel/-/async-channel-0.1.0.tgz","fileCount":9,"unpackedSize":33482,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJf/Pj+CRA9TVsSAnZWagAAcFkQAJmCWmYDfEpHWonFjDUR\nRPXJ7LSkNEcKrbefl1v4+DbtoX60NbecjWsH1Nc+lMjmaRYHLBMFpJqqA0qN\nlwQXNfDjAZOawt1AFTx+MY1PotS3s+DdwO4Lv45zPqJ16fuyFD1tnte7IVsn\nBDbkkyutraAv0ZaZo+f/9cQ4lB7TlQGF/74iPJymuNgaF2v1jSpEY5c0yFAf\ntM8U9O1jmHhkjmjwtgo8EuifvyrQozn3Sq4pIDboayON+DmSw3VA0x+KU7l7\nW8mFePQ4KPe2n9S0EqxNgHh7LnssHgbzOwoCcLnT2JqYfJiJuF5JSH+VS/+F\n/a/cA5vi+XjAxA5ooTcPXA96Y0fA6zF2Kaj2VjQs4opwOeEapu6WnFDFPmIV\nKlI6rJks3ec0cmI5n/q8+XnRXLo9fYqJYJextkdw2Mco4Y5BHHabcYYdKAQh\nExky2VTL2IGTU40HhjMzti0in3ByhwuF4gtGjaLH0E8FIF96tDa/sRj7HsVi\nl4K8kMbjMWhE9/PY7GZ0mTye58xgOaBUGEIWOR1FSA0R60ZM4pG0kSduc8AY\n3uFR5ZWP5NxrCfewpwZm2ZxOIpt0DVuQrJRNavQJ4kGQeSSg9ixodS7vAf8a\no5JJRELnEs3hRCT6lJQNbUiUPPxxkOU66zTjnFgF2rzKGJGm0kZ7A71vEzqk\nCDCS\r\n=XfSC\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIFlhCC4vUdv9dxpt7znLfwG/GRqYaXW5Zc1sqmzJnMZ8AiAaFB4sqtJ3ex6oHoJvJoiI+x91LNFBB9nSM4nvztwIhA=="}]},"_npmUser":{"name":"kyle1320","email":"kyle1320@gmail.com"},"directories":{},"maintainers":[{"name":"kyle1320","email":"kyle1320@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/async-channel_0.1.0_1610414334026_0.47970228394289327"},"_hasShrinkwrap":false},"0.1.1":{"name":"async-channel","version":"0.1.1","description":"Send asynchronous values across concurrent lines of execution","license":"ISC","repository":{"type":"git","url":"git+https://github.com/kyle1320/async-channel.git"},"author":{"name":"Kyle Cutler"},"main":"lib/index.js","types":"lib/index.d.ts","scripts":{"build":"tsc","test":"jest --env=node --colors --coverage test","lint":"eslint --ext .js,.ts .","docs":"typedoc src/index.ts"},"devDependencies":{"@typescript-eslint/eslint-plugin":"^4.11.1","@typescript-eslint/parser":"^4.11.1","eslint":"^7.17.0","eslint-config-prettier":"^7.1.0","eslint-plugin-prettier":"^3.3.0","jest":"^26.6.3","prettier":"^2.2.1","ts-jest":"^26.4.4","typedoc":"^0.20.13","typescript":"^4.1.3"},"keywords":["channel","coroutine","concurrent","async","await","promise","communication","parallel"],"gitHead":"9ed98e9d44fbf4288207d2a0441529c6a6f7ac64","bugs":{"url":"https://github.com/kyle1320/async-channel/issues"},"homepage":"https://github.com/kyle1320/async-channel#readme","_id":"async-channel@0.1.1","_nodeVersion":"12.20.0","_npmVersion":"6.14.8","dist":{"integrity":"sha512-i0VmrwPmZVV0EJmct7UdU3yYnI0HQRaUeGdKYSwv9BC3GY429RD559bhB7O9WK0ahSt5uBIzfzIlsCUe1fbnkQ==","shasum":"b46160a2a604691fb393c26009f02bc9b3703350","tarball":"https://registry.npmjs.org/async-channel/-/async-channel-0.1.1.tgz","fileCount":9,"unpackedSize":33448,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJf/kfqCRA9TVsSAnZWagAArq0QAJaFy2rKSYF5DZrt0wIl\nn97eDy9EBw/ys6tOwKQVM7lH9eKEmpYpR3gu0mKNeTRcOx8+oLdCuEegKMon\nAp4WEwUVlXCRwwu8JVYMSj0RNVrk7LAOHP1T+kxgNmRlv5qBbnf61oDM1Zjm\n8c+NPQ9L74rGnI1uatSgQKY9Fh7LmVIQnLHOiCzUi0RSIpGy3SuGfZBHdmIk\neuYRNJ+fMoQjYPTMdjdjQ3zEY0BhBWnkxZht+zmVbM5WCdb6v7dvj0MGqcqD\nPS9/dl0NGw8JPCFKv/VNO7kRdxG8h5cCyySef6bhxdH0CxguvlHYwiDCroVV\nL3foPz4ZVipuTlug4jFs3aFiuu6se7Dl2sd+kGq/C2+bjWXXmacHli9bkTc7\n+rPAZjLkl4rKiXEFOfPgyO5BFAMqKTdb6+KkYfkQUnmKPku2LjbCK16LJNg7\nrSM3VJRB4AbOga671OijlVe3StvYJvnN76fuXoM3G/1kJFILK1CzmjzB+e+9\nDzz1TGrismKl9FI+O0M+gVfzTz9nqTez57/CqlqtvmOtVoyQSprp6DQXiUbl\n9dFjcSk9B5gwnjk7hoFJulCoBIIFeVOeKthwKX7myLKQc9X9iwP09tyCLvhn\nyNqkydIVDu3Co+9GnkatRQ4emlo7hfaEWZtL1DVdq+nxnn3WcunzvJh2PHV8\nqW55\r\n=kTtQ\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCH3Zxd03aWrPqy2OrVksl3JcjOhLbluBZITIoh/qVSxMCIQDO3IrAcRXXaxZ+osztODJXKOH9VH/e5H4W8XcczKh+vw=="}]},"_npmUser":{"name":"kyle1320","email":"kyle1320@gmail.com"},"directories":{},"maintainers":[{"name":"kyle1320","email":"kyle1320@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/async-channel_0.1.1_1610500074158_0.8079016732819271"},"_hasShrinkwrap":false},"0.2.0":{"name":"async-channel","version":"0.2.0","description":"Send asynchronous values across concurrent lines of execution","license":"ISC","repository":{"type":"git","url":"git+https://github.com/kyle1320/async-channel.git"},"author":{"name":"Kyle Cutler"},"main":"lib/index.js","types":"lib/index.d.ts","scripts":{"build":"tsc","test":"jest --env=node --colors --coverage test","lint":"eslint --ext .js,.ts .","docs":"typedoc src/index.ts"},"devDependencies":{"@types/jest":"^26.0.20","@typescript-eslint/eslint-plugin":"^4.11.1","@typescript-eslint/parser":"^4.11.1","eslint":"^7.17.0","eslint-config-prettier":"^8.1.0","eslint-plugin-prettier":"^3.3.0","jest":"^26.6.3","prettier":"^2.2.1","ts-jest":"^26.4.4","typedoc":"^0.20.13","typescript":"^4.1.3"},"keywords":["channel","coroutine","concurrent","async","await","promise","communication","parallel"],"gitHead":"5732968f3638ae4b6f7a3d5117f48fc1f1b8bccd","bugs":{"url":"https://github.com/kyle1320/async-channel/issues"},"homepage":"https://github.com/kyle1320/async-channel#readme","_id":"async-channel@0.2.0","_nodeVersion":"12.21.0","_npmVersion":"6.14.11","dist":{"integrity":"sha512-BJyjI/sfKlyijaBt2hbOSxT28xGNtLR0QLzAKO1Hlnv5BULY7sAoYoTPW3lfr1ZIC7y+FxabxO9T8GXpyoofGg==","shasum":"4260a462e2fe3096f6cf59b5fb9b2e11a11b77bc","tarball":"https://registry.npmjs.org/async-channel/-/async-channel-0.2.0.tgz","fileCount":5,"unpackedSize":36655,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgRctdCRA9TVsSAnZWagAA2CQP/RvvgQmcgPJ7ih19d0jU\ni2Tox950Y8LoCw1Dbw/uV5C82TMdBpTrg/zK1fueybkc+k7z+Dai3bdPGBYt\nhWYWi0rTQY+NzpaonwYfnPwVklfcPaISoBkNwx0xEG+kFJ2oLD9lqSpUPxCY\nrcusxVPcwVMy+L5N3SHD8dps+uiIZ8kjCuOikZbe0go6FRKUb6Kn4hf3V436\nqjVhQ3AnmRxMNVTduLnri9ICHzCF58YUNAO0k77hrJbrGEuFI7AhS67iHfUO\nZpzwMcW1rmmt/fKscti+UWse9wtfG9+pyUEbxfD8VuHDsqSDtGsbM8ns7GqK\nnCJddsz37sYFs4Vx6C9yNC3cfI7zvU3Y/uItKg9o1xD9nMg1PXgasXUccdai\nhxkPXzLIyaknzpTWIDQAFWPRotjEsPabi7ojq6tKQVTfgBm5V3/pjBBx8daG\nKyxTCjL6zyEldGjyRUzrKB0mOVnkiSKVZcrS7LP5Fs0sFpmft0uMmiyyoeFG\ngTSVSelDBVdFukpf10QWKxBE672iIuK2ONFtsVoLa+p8PfkUZ5y4vagF30AR\nYGf3xAGH0oNYr/RxGMVDfwpI+LSLse0860USlJ1nGhjgE0SIOiRRDNTO2rWx\nGZuRZQ2n2lZC1AstViMv5/XN0Yt5F45iHe6LHj/h7G2Vtg096gA5oIq/JG1v\nkPeO\r\n=i6rr\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIApBDjpDzfMrfR5pz1iC4SUYl4Og0kMmC+56IKoX3N74AiBg0eBI2dsnVTFVS3GLdZdxAw1IkGTd3WENPae3Kg2VUQ=="}]},"_npmUser":{"name":"kyle1320","email":"kyle1320@gmail.com"},"directories":{},"maintainers":[{"name":"kyle1320","email":"kyle1320@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/async-channel_0.2.0_1615186780700_0.25777945490269816"},"_hasShrinkwrap":false}},"readme":"# async-channel: JavaScript Async Channels\n\n![CI Pipeline](https://github.com/kyle1320/async-channel/workflows/CI%20Pipeline/badge.svg)\n[![Coverage Status](https://coveralls.io/repos/github/kyle1320/async-channel/badge.svg?branch=main)](https://coveralls.io/github/kyle1320/async-channel?branch=main)\n[![npm](https://img.shields.io/npm/v/async-channel)](https://www.npmjs.com/package/async-channel)\n![license](https://img.shields.io/npm/l/async-channel)\n![npm bundle size](https://img.shields.io/bundlephobia/minzip/async-channel)\n\nasync-channel provides iterable, `await`able Channels for passing asynchronous values around, as well as tools for utilizing these Channels to perform parallel processing using a simple, functional API.\n\nZero dependencies, well-tested and works in all environments supporting ES6.\n\nReminiscent of Go channels (but don't let that distract you -- there are several differences).\n\n## Documentation\n\nDetailed API Documentation can be found [here](https://kyle1320.github.io/async-channel/).\n\n## Basic Usage\n\nCreate a Channel, passing an optional buffer capacity:\n\n```js\nconst chan = new Channel(0 /* default */);\n```\n\nNow do some asynchronous processing. For example:\n\n```js\nconst urls = [\n    \"https://www.google.com\",\n    \"https://www.microsoft.com\",\n    \"https://www.apple.com\",\n    // ...\n];\n\nfor (const url of urls) {\n    fetch(url).then(response => {\n        const text = response.text();\n\n        // push the response body to the channel\n        chan.push(text);\n    });\n}\n```\n\nThis will fetch each URL and send the body of each response over the Channel when complete. Here, `text` is a Promise, but plain values can be pushed to a Channel as well.\n\nNow all that's left to do is receive each result from the Channel:\n\n```js\ndo {\n    const text = await chan;\n    console.log(text);\n} while (!chan.done);\n```\n\nThis can be written more succintly using async iteration:\n\n```js\nfor await (const text of chan) {\n    console.log(text);\n}\n```\n\nThis is a simple example -- there are many more ways to use Channels.\n\n### Channel Closing\n\nClosing a Channel is often not necessary. However it can be useful if a downstream receiver needs to know when all values have been sent to the channel. It is also necessary for async iteration to complete. In the above example, the loops will never terminate as the Channel is never closed.\n\n`chan.close()` closes the channel, preventing further values from being sent. However, any buffered values or queued senders will remain on the Channel and continue to be processed.\n\nWhen all values have been received from the channel, it is considered \"done\" (`chan.done` will be `true`). At this point, any additional receivers will be rejected with a `ChannelClosedError`. If you are manually iterating over the Channel, you may want to handle this error gracefully (async iteration handles this automatically).\n\n### Error Handling\n\nJust as Promises can either resolve or reject, each item in a Channel can either be a value or an error.\n\nPromises passed to `chan.push()` will result in an error on the Channel if they reject. In addition, `chan.throw(err)` can be used to send an error over the Channel.\n\nAsync iteration over a Channel will stop when an error is encountered. Otherwise, errors are treated the same as normal values -- an error will not close, empty, or otherwise adversely affect the state of a Channel.\n\n### Receive a Single Value\n\nUse `chan.get()` to receive a single value from a Channel. This method returns a Promise that resolves or rejects with the next value or error on the Channel:\n\n```js\nchan.get().then(\n    value => console.log(value),\n    error => console.error(error)\n);\n```\n\nChannels also have a shorthand `then()` method that is compatible with Promises and `async`/`await` syntax, so the above can also be written as:\n\n```js\ntry {\n    const text = await chan;\n    console.log(text);\n} catch (err) {\n    console.error(err);\n}\n```\n\n### Waiting for Consumption\n\nIn the above example, we simply send a value to the channel and forget about it. But sometimes it is useful to wait for the value to be received before proceeding (if you're familiar with Go channels, this should make sense to you).\n\nFor these scenarios, `chan.push()` and `chan.throw()` return a Promise that resolves when the value has been accepted by the Channel -- either when it has been inserted into the Channel's buffer (if the buffer capacity is not 0), or when it has been received.\n\n### Multiple Receivers\n\nIf multiple receivers are pulling from the same Channel, only one will receive each item. This can be useful to create multiple \"worker threads\" (or coroutines) that receive and process values from a channel, and then push them into a result channel.\n\n## Functional Utility Methods\n\nIn fact, this multi-receiver pattern is so useful that Channels have several methods for performing \"multi-threaded\" functional operations such as `map` and `filter` over their values, while utilizing concurrency. For example:\n\n```js\n  Channel.from(urls)               // or any Channel\n    .map(fetch, null, 3)           // Perform up to 3 requests concurrently\n    .filter(\n        res => res.status === 200, // ignore non-OK status codes\n        err => false               // ignore errors\n    )\n    .map(res => res.text())\n    .forEach(text => console.log(text));\n```\n\nThis is similar to the above example, but limits the number of simultaneous requests to 3, and returns a Promise that resolves after all processing has been completed.\n\n## `BaseChannel` class\n\nIf you are only using Channels for basic communication (without any of the functional methods or iterators), you can just use the `BaseChannel` class. This can be useful for tree-shaking the unused code.\n\n## `IteratorChannel` Class\n\nIt can be useful to create a Channel which simply pulls its values from an iterable source. This is most useful for scenarios like the above example, where the input elements are pre-defined or easily generated","maintainers":[{"name":"kyle1320","email":"kyle1320@gmail.com"}],"time":{"modified":"2022-06-13T03:36:29.787Z","created":"2014-05-10T23:02:00.236Z","0.0.0":"2014-05-10T23:02:00.236Z","0.1.0":"2021-01-12T01:18:54.158Z","0.1.1":"2021-01-13T01:07:54.309Z","0.2.0":"2021-03-08T06:59:40.863Z"},"author":{"name":"Kyle Cutler"},"license":"ISC","readmeFilename":"README.md","homepage":"https://github.com/kyle1320/async-channel#readme","keywords":["channel","coroutine","concurrent","async","await","promise","communication","parallel"],"repository":{"type":"git","url":"git+https://github.com/kyle1320/async-channel.git"},"bugs":{"url":"https://github.com/kyle1320/async-channel/issues"}}