{"_id":"n-barrier","_rev":"1-1b6738f55dc1a16e7a3fbf5ec82f5b96","name":"n-barrier","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"n-barrier","version":"1.0.0","description":"Simple barrier implementation for syncing multiple asyncronouse tasks","main":"index.js","scripts":{"build":"tsc","test":"npm run-script build && jest"},"author":{"name":"Mario Jäckle"},"license":"MIT","bugs":{"url":"https://github.com/jacksbox/n-barrier/issues"},"homepage":"https://github.com/jacksbox/n-barrier#readme","repository":{"type":"git","url":"git+https://github.com/jacksbox/n-barrier.git"},"devDependencies":{"jest":"^24.9.0","typescript":"^3.6.3"},"gitHead":"686afecca099d5c8b4d973580bf7c43dde57b5f8","_id":"n-barrier@1.0.0","_npmVersion":"6.1.0","_nodeVersion":"9.0.0","_npmUser":{"name":"jacksbox","email":"npm@jacksbox.de"},"dist":{"integrity":"sha512-qyghZkX9DeD/XSZghL/7ewWDXJVK/CZB+Lb4KmAElweT2l6YoFclSwyPkIxZg+inFdWjGNY7oyVNGGKUakDMzg==","shasum":"86aaefe2a4a46db4458e59dd79b9ba2dd126d11e","tarball":"https://registry.npmjs.org/n-barrier/-/n-barrier-1.0.0.tgz","fileCount":6,"unpackedSize":11371,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJdmi/RCRA9TVsSAnZWagAA/PMQAIRog4w/dYCLFVjqwUCZ\nVaO3rSzSIMS1mhTIznxsEk+BKGC6T31LMhz+L+eOBOd4yU83VWUYNZzlmTwu\ndt4N/YThwYJ7Sq5VEQJFbdSpuR7d31ffm+p+hmSNw5QOKw7djMibYA0pN1Se\nYRURgAMrBp7rMMsKU7sPlguZ5MOj8Q+bLu8iWO52KiJGMRFfu1G7UYXq+Ckl\n7HilXxoMqQThzwX259JABsSjkCl/w+gG/qIlsWQ5Yd4lG1B3WOJMIwRcGuY6\nIAxSPYw3+pTjDY0zSG2/3SwRkB7S7XlOPFBwPb6n273dR0U8vEHeLeD7o0Nh\ntZlwLGNmefOKMFY2wcfOf9jWFo3GmsEpEOV+WPR4Qqj8+QzePqgcr0Bs3aAe\nVYy87ekyINz9oft5vgD0j9UMiJ8KTCXmZkltHAej861SSv1s2hu2/piYJWN+\nzQTXkr4rpNZlMn6SXNx6iyQmCf/s30AyDpwOSdfNHJDEtC2HKExm+PfTQmtw\nLzVuEeWyxdlGZhuFjrKtdVLO9ogQQgSJrSX/gqzc36Stp8FY9h8gsGiMw68l\nRL9WPBWxW50CQLKVDJDZeO1VxCVV78dGk6Ug91tG+YlR40y/Iy44rlm4zGj3\nHKh5s2qUKhWQJObaF0f2QvhRVqTDKkEnpbl+hEzg2OddIkrssdxb7aNdz286\naQDD\r\n=1/di\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQC3sn8IWE3GSSDvAIcfwztqCNWw0OcWGOZ8GV/y2lD7eAIhALuVsIu9F8OlreFe5YLrYms6700ys9zFFpFJXesxeHBW"}]},"maintainers":[{"name":"jacksbox","email":"npm@jacksbox.de"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/n-barrier_1.0.0_1570385873071_0.9827881135271785"},"_hasShrinkwrap":false}},"time":{"created":"2019-10-06T18:17:53.071Z","1.0.0":"2019-10-06T18:17:53.258Z","modified":"2022-05-10T08:00:29.452Z"},"maintainers":[{"name":"jacksbox","email":"npm@jacksbox.de"}],"description":"Simple barrier implementation for syncing multiple asyncronouse tasks","homepage":"https://github.com/jacksbox/n-barrier#readme","repository":{"type":"git","url":"git+https://github.com/jacksbox/n-barrier.git"},"author":{"name":"Mario Jäckle"},"bugs":{"url":"https://github.com/jacksbox/n-barrier/issues"},"license":"MIT","readme":"# n-barrier\n\nSimple barrier implementation for syncing multiple asyncronouse tasks.\n\nProvides two barrier implementations:\n* `nBarrier` which wait for `n` tasks to reach their `.wait()` instruction\n* `pBarrier` which waits for passed in promisses to resolve\n\n## installation\n\n`npm install n-barrier`\n\n## usage\n\n### nBarrier\n\nLet `n` tasks wait for each other before continuing execution.\n\n#### example\n\n```js\nconst { nBarrier } = require('n-barrier')\nconst barrier = nBarrier(3) // barrier which wait for 3 tasks before opening\n\nconst startTask = time => setTimeout(() => {\n  await barrier.wait() // tasks wait here before 3 tasks in total reach this point\n  console.log('finished')\n}, time)\n\nstartTask(0)\nstartTask(0)\nstartTask(1000)\n// no console output for the first 1000ms then\n// all 'finished' messages will be logged at once\n```\n\n### pBarrier\n\n`pBarrier` works similar to `Promise.all` but you will get back a `barrier` instance with\na `wait()` method you can pass around to await the resolvement at multiple locations.\n\n```js\nconst { pBarrier } = require('n-barrier')\n\nconst startTask = time => new Promise(resolve => setTimeout(() => {\n  resolve()\n}, time))\n\nconst asyncTaskWithBarrier = async barrier => {\n  // ...do some stuff\n  await barrier.wait() // wait for the other tasks to finish\n  console.log('asyncTaskWithBarrier continues')\n}\n\nconst barrier = pBarrier(startTask(0), startTask(0), startTask(1000))\n\nasyncTaskWithBarrier(barrier) // starts another aync task\n\nawait barrier.wait()\nconsole.log('all tasks finished') // will only be logged after 1000ms (after each promise resolved)\n```\n","readmeFilename":"README.md"}