{"_id":"@lorenzofox3/for-await","_rev":"6-d89e6df8b6e13cb58cae9342f60c43ee","name":"@lorenzofox3/for-await","dist-tags":{"latest":"0.2.2"},"versions":{"0.1.0":{"name":"@lorenzofox3/for-await","version":"0.1.0","description":"operator and stream utilities for async iterators","main":"index","engines":{"node":">=9.3.0"},"directories":{"test":"test"},"scripts":{"build":"babel *.mjs lib/*.mjs --out-dir .","test":"node --harmony --experimental-modules ./test/index.mjs | tap-diff"},"keywords":["stream","for-await","reactive-programming","iterator","async-iterator","asyncIterator","generator","async"],"author":{"name":"Laurent Renard"},"license":"MIT","devDependencies":{"babel-cli":"^6.26.0","babel-plugin-dynamic-import-node":"^1.2.0","babel-plugin-syntax-async-generators":"^6.13.0","babel-plugin-transform-es2015-modules-commonjs":"^6.26.0","tap-diff":"^0.1.1","zora":"^2.0.0-0"},"dependencies":{},"gitHead":"664d9d1725341b5fd4718ca674960dd9d9562063","_id":"@lorenzofox3/for-await@0.1.0","_npmVersion":"5.5.1","_nodeVersion":"9.3.0","_npmUser":{"name":"lorenzofox3","email":"laurent34azerty@gmail.com"},"dist":{"integrity":"sha512-YR4EIPtTTOY722EH8S2j6bk9qQAiViSgpRLqjTJOg9ZQveEmvcg2KU5GqFx0mkZhjDM4tNzOWKC7ln5ldzEJ4g==","shasum":"f378d3d4717432c2bf071236626f023656433394","tarball":"https://registry.npmjs.org/@lorenzofox3/for-await/-/for-await-0.1.0.tgz","fileCount":12,"unpackedSize":20953,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIATEphED4eraAIBsLVyJdJifsfbg9FbE3ws4l1jjIIHOAiACqnVGDTzaEOWxEhqU1ZxoGhb4q/sDIldbbTFKd3xvxg=="}]},"maintainers":[{"name":"lorenzofox3","email":"laurent34azerty@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/for-await_0.1.0_1518560036095_0.2231930604189143"},"_hasShrinkwrap":false},"0.2.0":{"name":"@lorenzofox3/for-await","version":"0.2.0","description":"operators and stream utilities for async iterators","engines":{"node":">=9.3.0"},"directories":{"test":"test"},"main":"./dist/bundle/index","module":"./dist/bundle/module.js","types":"./dist/bundle/index.d.ts","scripts":{"build:clean":"rm -rf ./dist && mkdir -p ./dist/bundle ./dist/declarations","build:bundle":"rollup -c ./rollup/build.js && cp ./src/index.d.ts ./dist/declarations/","build":"npm run build:clean && npm run build:bundle","test":"rollup -c ./rollup/test.js --output.format cjs | node","test:ci":"rollup -c ./rollup/test.js --output.format cjs | node | tap-diff","example:node":"rollup -c ./examples/scripts/rollup.node.js | node"},"keywords":["stream","for-await","reactive-programming","iterator","async-iterator","asyncIterator","generator","async"],"author":{"name":"Laurent Renard"},"license":"MIT","devDependencies":{"rollup":"^0.67.4","rollup-plugin-commonjs":"^9.2.0","rollup-plugin-node-resolve":"^3.4.0","tap-diff":"^0.1.1","zora":"^2.0.1"},"dependencies":{},"gitHead":"a0daa5912a96172fcfe548b37673d2608426eb43","_id":"@lorenzofox3/for-await@0.2.0","_npmVersion":"6.5.0","_nodeVersion":"10.11.0","_npmUser":{"name":"lorenzofox3","email":"laurent34azerty@gmail.com"},"dist":{"integrity":"sha512-lStNOGPT2YNE9BnmqwIOj3+CP1g7Y+kAMzVko8rMMbGRQAVXrp+nHOiCKmqyGiL4d+dvIdeFvcPOcf1vK2b48A==","shasum":"f95b35f378a5f85f21e38d831bf7734a5b4f645e","tarball":"https://registry.npmjs.org/@lorenzofox3/for-await/-/for-await-0.2.0.tgz","fileCount":8,"unpackedSize":39686,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcGR4NCRA9TVsSAnZWagAA0lcP/3+FdKG2b10p62zvRycl\nkovJ3q5VTD5jGwFuhomRajqebaKvJADhKjIXaYpJbmlllTp2WDNKxVvrlDpy\nRG7KjaY4sXbhNSWpUr0jgqwfHQW3SETEssbRw7sknlY+hm++wmOeCnrA8gUt\nEWtH/yvHV/G3313v2wQi5UpWeMEgEbZPW220CdQkiZSe5U12IQui4uamyMu7\nF1EWLTrH8/oQt+HsL0WmTeFsECSGhFQwkdIPNB3G2v2vnwLalyB53/gNSGlK\nL3mGFcckH1rqhBDXK5FDvCCSAeHh8TJd5dKvEchYahT90raFPrn44ZcnfxoE\nk417snMc62KbNXJUEOK09EwKOkk0Yaw3kTsiu0ZB6HdEgpSjRpJtQ9RJxo8V\nWwH0Tp/D0GnZyy+EepZBrPDh/B0/Oyo4BtFlLptqi28pGVYfOrrnlQwkg0be\n1jg2xDl7SuhD5lk2jh/IrJ+KKFTA8KcQrnJCyt5McUCM6IiIjaokzf+OOQi3\nK+Y5JwrMb7nvNaq5U6d2R7Mj1dmr3MUxNbDQnrRw8nOmyJnNUzwljL4Y8h7X\nw08OVCIHPGhhBpupMIAPTR/Ut+yKzsZnbGKu0pbEKNYb9j64RRDPLRenqb+o\nZ48PYO/nK/ijBex5NDd1AL7OITa6csMoi9iZ0axSz+Vmo1IgiLigRd55yfki\nBw20\r\n=PPwI\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIGswo9Qe75+mc2q0IEVrZ6jRf2opts2QkEW4vsAL0XbjAiBAJ9DMnUvNRdeRmqdDy7eSd3RpeVAqEoYGnZxnYuOr/Q=="}]},"maintainers":[{"name":"lorenzofox3","email":"laurent34azerty@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/for-await_0.2.0_1545149965278_0.17724056947126687"},"_hasShrinkwrap":false},"0.2.1":{"name":"@lorenzofox3/for-await","version":"0.2.1","description":"operators and stream utilities for async iterators","engines":{"node":">=9.3.0"},"directories":{"test":"test"},"main":"./dist/bundle/index","module":"./dist/bundle/module.js","types":"./dist/bundle/index.d.ts","scripts":{"build:clean":"rm -rf ./dist && mkdir -p ./dist/bundle ./dist/declarations","build:bundle":"rollup -c ./rollup/build.js && cp ./src/index.d.ts ./dist/declarations/","build":"npm run build:clean && npm run build:bundle","test":"rollup -c ./rollup/test.js --output.format cjs | node","test:ci":"rollup -c ./rollup/test.js --output.format cjs | node | tap-diff","example:node":"rollup -c ./examples/scripts/rollup.node.js | node"},"keywords":["stream","for-await","reactive-programming","iterator","async-iterator","asyncIterator","generator","async"],"author":{"name":"Laurent Renard"},"license":"MIT","devDependencies":{"rollup":"^1.27.14","rollup-plugin-commonjs":"^10.1.0","rollup-plugin-node-resolve":"^5.2.0","tap-diff":"^0.1.1","zora":"^3.1.8"},"dependencies":{},"gitHead":"cf174f6e81ad142e7a1a2b1f83b32535a7922c9f","_id":"@lorenzofox3/for-await@0.2.1","_nodeVersion":"12.13.1","_npmVersion":"6.13.4","dist":{"integrity":"sha512-fMpDQioAnl0a97Y3sKTpX8iWidQ1EkmsGh09YTnQrwBgRBZAbBaMF5WGdfYPUMY7qWiQuvDqgwKbuyvW6MRDBA==","shasum":"cb12c2bba25eaca8225db06027820624c5d2f5e5","tarball":"https://registry.npmjs.org/@lorenzofox3/for-await/-/for-await-0.2.1.tgz","fileCount":8,"unpackedSize":39686,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJeB1roCRA9TVsSAnZWagAAES0P/0nFnp8qfyztmixD+HKq\nR6KP/1KTnGA8xJuuyuUVBhvLmwZEWoUrAUTMrSaPEfwwB/0kYDKD+QgBlFXi\njCSeFCu5HCqOzT7/TXoevkW2JYoA22MI3JT0gktyVaO4pRWHrg2e51TrG1LM\nem0mtMXHmjAGxC/6iUfMYMK326gVoJND2NMTSli2+Gi7W5/zEnnkC6YuG9BU\nv4swooSIfNXobWp42k7H3t8nMKnNJE1auz5sf4PQkXVrG4v7vucjOQnYRrlz\nYxjRXqa2WZe4P34PJs9GvtI+lTbxXxLZEA1V/Iq/l2Smh1Jo4ItHzZWCnj8n\ne61RXDsVaMIiVdfEqv2ycDtclSYgNIX8scv7be0qbzwRkoYBb4UKjF1O15M9\nRBoINJJ+VbGLtwcFIqG7gdQrubC1T4h3x9+8ftscUre5cHwmBg8RLH0bFRI8\n3eA+NmIxZRbUSDEjTzfZlzmjR4juH7HIOwiQ7bV9GzPnuwFiJZvWr44fPGW3\nZ7+YbxIzKr2D2vboyVuM9cVSvWCIa+RAwwsfBLym4BmfnFrW5ggnL0vZuKok\n0MfKM5z3xruiuJKJTfcBvKX1dASAZVtkzB1dV0wVkUcLw6tim7JaNoKbxz2E\ncvy/Zzky2kef0xXnjAsrzH07ex+iSh3D59vgvK+E37BTMZnWZuinZlJECLUE\nq8j4\r\n=qc95\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIDDTK/ec3OGdQuYPEQhBf5gfk4HwGSNkOPKsc+T40/DGAiEAhWWQ3G0+75wvw8w3Kn/DrFopCrc8t5fmv1CIMt8k3XQ="}]},"maintainers":[{"name":"lorenzofox3","email":"laurent34azerty@gmail.com"}],"_npmUser":{"name":"lorenzofox3","email":"laurent34azerty@gmail.com"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/for-await_0.2.1_1577540328173_0.4829930110262777"},"_hasShrinkwrap":false},"0.2.2":{"name":"@lorenzofox3/for-await","version":"0.2.2","description":"operators and stream utilities for async iterators","engines":{"node":">=9.3.0"},"directories":{"test":"test"},"repository":{"type":"git","url":"git+https://github.com/lorenzofox3/for-await.git"},"main":"./dist/bundle/index","module":"./dist/bundle/module.js","types":"./dist/bundle/index.d.ts","scripts":{"build:clean":"rm -rf ./dist && mkdir -p ./dist/bundle ./dist/declarations","build:bundle":"rollup -c ./rollup/build.js && cp ./src/index.d.ts ./dist/declarations/","build":"npm run build:clean && npm run build:bundle","test":"rollup -c ./rollup/test.js --output.format cjs | node","test:ci":"rollup -c ./rollup/test.js --output.format cjs | node | tap-diff","example:node":"rollup -c ./examples/scripts/rollup.node.js | node"},"keywords":["stream","for-await","reactive-programming","iterator","async-iterator","asyncIterator","generator","async"],"author":{"name":"Laurent Renard"},"license":"MIT","devDependencies":{"rollup":"^1.27.14","rollup-plugin-commonjs":"^10.1.0","rollup-plugin-node-resolve":"^5.2.0","tap-diff":"^0.1.1","zora":"^3.1.8"},"dependencies":{},"gitHead":"9e93768f5c1a34521db465919551c6df003702b1","bugs":{"url":"https://github.com/lorenzofox3/for-await/issues"},"homepage":"https://github.com/lorenzofox3/for-await#readme","_id":"@lorenzofox3/for-await@0.2.2","_nodeVersion":"16.3.0","_npmVersion":"7.15.1","dist":{"integrity":"sha512-IKIjQAyl6yu/kWTCqpc4QQwkA048pgsvvwxb8bMoqC4NBdypVBGj0wxFTL882sw8WzMSpov3g/pP6RxPhqbJHA==","shasum":"64e989dcd16941da9e808687f401f9680de6ae85","tarball":"https://registry.npmjs.org/@lorenzofox3/for-await/-/for-await-0.2.2.tgz","fileCount":8,"unpackedSize":39786,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJh2PdACRA9TVsSAnZWagAAJDIP/RxR3LNEpYYBTZuT7QJ1\nIfEufBESDanXE+DoVxYgptwWHFTMTiDVLkm/OdPcRmFc9DlEshvvvblMBEN3\n6KGjKp23GvXia/zzL3eE3zbXlpcI30J7rSCKwcAh+GQCXME6fxA2L6Jr/jzw\nSD5XK48J1bBZY35VIJbRbiwFpwAyYmCESdjJMex2gVdI57pcdoOVaQs+K6Ep\nbS5X878tyZCSVbmY6c32KVlmA2SDPMOO+4UjEaWTdVkx4K1nchSxMpmt5JRC\ncExFNMbe75/fiuzPqwYF4HTNSik+n7y13tDyvaOMz8eZ0mdMDjiVtSK3rhgc\niqCNctnDze3/hD3P2fy7mTz3pZ/tLd45Ou1QDKLk2LNOhBvkD9d7+p8yi/JZ\nD71V3E1a7sj1FOVMsydBbcDaSMfEntBTXGRcMGFd7Mbq72+7Qt9A/eLxw9f3\nZw3Cq5KlLJYSiK7OayEJbBxoyhSt+cIaAB3xy33Ty3aEM/3hfJRSqPFtoMjq\nRNQCYvGNE2/TsDQryI0WcYfFAjUmNAJyNWMuRvgr15t1LTlR5sPm+EUc8Rf4\nOJjEockLSlA27Mye8+MksRQ7cJMvmdBq/QkC2x1KE0D0Lww2eURbHuWClRlv\nHNDXt2Un+dNSeA6/OfYkilMVcOexGMsG7PrSXozGwONjmDgIHT5upAPkVe++\nDYsG\r\n=Rx8Z\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCBu5kRrN5R0FhssdWpnRu94F0HmJYm0HEtaYY0A/5vGwIhAI/kZBZbeZ72LAe40iE2T+91ngoGHEAlj6jWTpPG42Qo"}]},"_npmUser":{"name":"lorenzofox3","email":"laurent34azerty@gmail.com"},"maintainers":[{"name":"lorenzofox3","email":"laurent34azerty@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/for-await_0.2.2_1634545082514_0.6905208616482432"},"_hasShrinkwrap":false}},"time":{"created":"2018-02-13T22:13:55.765Z","0.1.0":"2018-02-13T22:13:56.778Z","modified":"2022-04-06T02:27:39.069Z","0.2.0":"2018-12-18T16:19:25.453Z","0.2.1":"2019-12-28T13:38:48.314Z","0.2.2":"2021-10-18T08:18:02.631Z"},"maintainers":[{"name":"lorenzofox3","email":"laurent34azerty@gmail.com"}],"description":"operators and stream utilities for async iterators","keywords":["stream","for-await","reactive-programming","iterator","async-iterator","asyncIterator","generator","async"],"author":{"name":"Laurent Renard"},"license":"MIT","readme":"[![CircleCI](https://circleci.com/gh/lorenzofox3/for-await.svg?style=svg)](https://circleci.com/gh/lorenzofox3/for-await)\n\n# for-await\n\nOperators and stream semantic for asyncIterators.\n\n``npm install @lorenzofox3/for-await``\n\n## Motivation\n\n[AsyncIterator](https://tc39.github.io/proposal-async-iteration/#sec-asynciterator-interface) and [AsyncGenerator](https://tc39.github.io/proposal-async-iteration/#sec-asyncgenerator-objects) (and the `for await` statement to consume them) have been integrated into es2018 specification and have started to land in different Javascript engines:\n\n1. Nodejs > v9 (with harmony flag for some versions)\n2. Chrome\n3. Firefox\n\nThey provide a new way to create data structures which have the semantic of readable streams: ie that produce values in time (asynchronously)\n\n```Javascript\nconst wait = (time = 100) => new Promise(resolve => {\n  setTimeout(() => resolve(),time);\n});\n\n// produce a sequence of integer every 100ms\nconst counter = async function * (limit = 5){\n    let i = 0;\n    while(true){\n        if(i >= limit){\n            break;\n        }\n        await wait();\n        yield i;\n        i++;\n    }\n}\n\n// consume it\nfor await (const i of counter()){\n    console.log(i);\n}\n\n// > 0 (after 100ms)\n// > 1 (after 200ms)\n// ..\n// > 4 (after 500ms)\n```\n\nAnd this is very powerful !\n\nThis library aims at providing operators and data structures with almost the same API than regular synchronous collections (like Array) implement, so you can manipulate\nthese streams as if they were synchronous collections.\n\n```Javascript\nimport {stream} from 'for-await';\n\nconst oddSquaredCounter = stream(counter())\n    .filter(i => i % 2 === 0) // keep odd\n    .map(i => i * i) // square it\n\n// and consume it\n\nfor await (const v of oddSquaredCounter){\n   console.log(v);\n}\n\n// > 0 (after 100 ms)\n// > 4 (after 300 ms)\n// > 16 (after 500 ms)\n```\n\nThis could sound familiar to anyone who has already tried [reactive programming](https://en.wikipedia.org/wiki/Reactive_programming) or have used the same kind of abstractions on streams provided by some nodejs libraries (like [through](https://www.npmjs.com/package/through2)).\n\nHowever this implementation relies only on native EcmaScript features which makes it very lightweight and easier to use on different platforms.\n\nYou will only have to implement an adapter (I will likely write modules for common data source in Nodejs and in the Browser) so your data source implements the standard asyncIterator interface (and this has become way more easier with async generators).\n\n[See our csv parser for nodejs and browser]('./examples').\n\n## Operators\n\n### semantic\nIf you are not familiar with the synchronous iterable/iterator protocol, I strongly recommend the [Reginald Braithwaite book](https://leanpub.com/javascriptallongesix) and [his essays](http://raganwald.com/2017/07/22/closing-iterables-is-a-leaky-abstraction.html)\n\nNote all the operators which do not return a scalar value follow the same semantic than the underlying source:\n1. If source streams are consumable once the resulting iterable is consumable once\n2. If source streams implements control flow hooks (like return or throw), these hooks will be called as well so your data source is properly released etc\n\nFor example in a synchronous world you already know that\n```Javascript\nconst array = [0,1,2] // implements Iterable protocol\n\nfor (const i of array){\n    console.log(i);\n}\n\nfor (const i of array){\n    console.log(i);\n}\n\n// > 0\n// > 1\n// > 2\n// > 0\n// > 1\n// > 2\n\n// However\n\nconst counterGen = function * (){\n    yield 0;\n    yield 1;\n    yield 3;\n}\n\nconst oneTwoThree = counterGen();\n\nfor (const i of onTwoThree){\n    console.log(i);\n}\n\nfor (const i of onTwoTree){\n    console.log(i);\n}\n\n// > 0\n// > 1\n// > 2\n// And nothing as the generator is already exhausted\n```\n\nThe will be the same for our async iterators\n```Javascript\nimport {map} from 'for-await';\n\n// Assuming the asynchronous counter of the introduction\nconst zeroOneTwoSquared = map(x=>x*x, counter(3));\n\nfor await (const i of zeroOneTwoSquared){\n    console.log(i);\n}\n\nfor await (const i of zeroOneTwoSquared){\n    console.log(i);\n}\n\n// > 0 (100ms)\n// > 1 (200ms)\n// > 4 (300ms)\n// And nothing as the generator is already exhausted\n\n//However\n\nconst iteratable = {\n    [Symbol.asyncIterator]:counter\n}\n\nfor await (const i of iterable){\n    console.log(i);\n}\n\nfor await (const i of iterable){\n    console.log(i);\n}\n\n// > 0   (100ms)\n// > 1   (200ms)\n// > 4   (300ms)\n// > 9   (400ms)\n// > 16  (500ms)\n// > 0   (600ms)\n// > 1   (700ms)\n// > 4   (800ms)\n// > 9   (900ms)\n// > 16 (1000ms)\n```\n\nMost of the operators are curried:\n\n```Javascript\nimport {map} from 'for-await';\n\nconst square=map(x=>x*x);\n\nfor await (const i of square(counter()){\n // do something\n}\n\n//and another one\nfor await (const i of square(counter()){\n // do something\n}\n```\n\n### operators list\n\n#### return a new Async Iterable\n1. map\n2. filter\n3. slice\n4. flatMap (flatten stream of streams)\n5. concat\n\n#### Return a scalar (as a promise)\n1. reduce\n2. find\n3. findIndex\n4. includes\n5. every\n6. some\n\n## Data structure\n\nEven more convenient you can use the stream data structure which gives you almost the same API than Arrays.\n1. An instance of a stream will implement all the operators above\n2. Every method which returns an async Iterable will actually return a new instance of stream (so you can chain them together)\n","readmeFilename":"README.md","homepage":"https://github.com/lorenzofox3/for-await#readme","repository":{"type":"git","url":"git+https://github.com/lorenzofox3/for-await.git"},"bugs":{"url":"https://github.com/lorenzofox3/for-await/issues"}}