{"_id":"@antonbarinov/event-emitter-async","_rev":"3-1bf4edf92b27c7938019f0c1e8a029f2","name":"@antonbarinov/event-emitter-async","dist-tags":{"latest":"1.0.1"},"versions":{"1.0.0":{"name":"@antonbarinov/event-emitter-async","version":"1.0.0","description":"Asynchronous with async/await","main":"index.js","dependencies":{},"devDependencies":{},"scripts":{},"author":{"name":"Barinov Anton"},"keywords":["modules"],"license":"MIT","repository":{"type":"git","url":"git+https://github.com/antonbarinov/AsyncEventEmitter.git"},"bugs":{"url":"https://github.com/antonbarinov/AsyncEventEmitter/issues"},"homepage":"https://github.com/antonbarinov/AsyncEventEmitter","_id":"@antonbarinov/event-emitter-async@1.0.0","_npmVersion":"5.6.0","_nodeVersion":"9.7.1","_npmUser":{"name":"antonbarinov","email":"markelov.69@bk.ru"},"dist":{"integrity":"sha512-bCmYhau0SXUW7CUtS1GdlkdbkWPW5Sx6NwIVC8RoBaGycpLzUqHaIkRigI4Hhnd7MXmm/asfsO+vJzNv0eptYw==","shasum":"10b8080801df03a253a08bf55fbfac5959744a36","tarball":"https://registry.npmjs.org/@antonbarinov/event-emitter-async/-/event-emitter-async-1.0.0.tgz","fileCount":12,"unpackedSize":24341,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCICmklnWjBP/oN4h5TKHGGYNwv76jXy6cM6G4ost+RQDJAiEA2OgGEc4+fbM4R5EOwpGUM9OBLKJWcKKs9p4+Is73AnA="}]},"maintainers":[{"name":"antonbarinov","email":"markelov.69@bk.ru"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/event-emitter-async_1.0.0_1523650628642_0.4993028362038969"},"_hasShrinkwrap":false},"1.0.1":{"name":"@antonbarinov/event-emitter-async","version":"1.0.1","description":"Asynchronous with async/await","main":"index.js","dependencies":{},"devDependencies":{},"scripts":{},"author":{"name":"Barinov Anton"},"keywords":["modules"],"license":"MIT","repository":{"type":"git","url":"git+https://github.com/antonbarinov/AsyncEventEmitter.git"},"bugs":{"url":"https://github.com/antonbarinov/AsyncEventEmitter/issues"},"homepage":"https://github.com/antonbarinov/AsyncEventEmitter","_id":"@antonbarinov/event-emitter-async@1.0.1","_npmVersion":"5.6.0","_nodeVersion":"9.7.1","_npmUser":{"name":"antonbarinov","email":"markelov.69@bk.ru"},"dist":{"integrity":"sha512-z7KTLe3k4zsicJ1A/SAqzlml7HnBgYWF5LRLBYodlRw+69rRXSp2wySNhN4F2D1jSjQfSHgfIHJtSrVuYdyjvg==","shasum":"707bd942beb0e1379e03e0d2cf9543c31f3e4240","tarball":"https://registry.npmjs.org/@antonbarinov/event-emitter-async/-/event-emitter-async-1.0.1.tgz","fileCount":12,"unpackedSize":23704,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJa70ECCRA9TVsSAnZWagAAwtwP/2PmpQ7OHAB05RQ1rfet\nJqf7fH+TLz1YE3TCbv/F0VKPW9lynqiT6uzUkxRdrVtcLGF5wDpgTUSmbKMr\njlPpiPT/+vn0Y/RkcVgIYsRInB+aesUOw9LVnT+aAJLfwCPheOnxv1Bxi1v+\nBN2/olaR5fkq+KT9q2gRVNShH3h6JyuJGO05qVBJf2W2goypvtBcAKaF37sK\nCDVuoHSfXjBbKIN4ePdAxfqlVYOFs1vmIhj3BQ/YIxFY11UK6KwjGrvOfzP4\nKbkHZwf5z9fI9X5olNzcjn3h2T0NoNImrdjCSCZFnGNO+mscAWHIpi/dTEw8\nZ4B8ZFkYfwsJvDzFDhSsSyxeQBSHRTbHAmLCsxnWGsD62CwAP0iH2ToEemed\nuYGKy+2J2sPDKO3wimYkegv7votOgXrzIdeD4R5PDHaGt/gX+lmu4jqtGbZo\nsRSQi1V/B1mbkRFWkCRQndwboemEzsD1hY3SNxtqFxFRtUmo5fNHtEJYv75e\nx5xRtgccY7EppAkew9DZOpblp7v3a7cAlgAgHkkiiPQbgplMZzKPsbL0ZAU7\nrni5lId29dEq8z8aTjn9+MR/IG4ou4IMaGx/U2aAvfd9QVBkh9EiS1Nd7+gw\nx66pA4ceu3Ud1ffeA8zPQSgXbMgZwyWCjojmJYvSEtSlWXLBBE3EH/Dt4kgI\nwpXt\r\n=ouQf\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDmwtJMz3cO2DAanR/in8cxQ1hwynfeNk8Z6Iqsl+OoUgIgClcs24BZFDTW58+uRX26LERBbhAiOGGF+xddkIJyuVU="}]},"maintainers":[{"name":"antonbarinov","email":"markelov.69@bk.ru"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/event-emitter-async_1.0.1_1525629185488_0.23844593284643323"},"_hasShrinkwrap":false}},"time":{"created":"2018-04-13T20:17:08.588Z","1.0.0":"2018-04-13T20:17:08.715Z","modified":"2022-04-04T14:23:06.246Z","1.0.1":"2018-05-06T17:53:05.561Z"},"maintainers":[{"name":"antonbarinov","email":"markelov.69@bk.ru"}],"description":"Asynchronous with async/await","homepage":"https://github.com/antonbarinov/AsyncEventEmitter","keywords":["modules"],"repository":{"type":"git","url":"git+https://github.com/antonbarinov/AsyncEventEmitter.git"},"author":{"name":"Barinov Anton"},"bugs":{"url":"https://github.com/antonbarinov/AsyncEventEmitter/issues"},"license":"MIT","readme":"# AsyncEventEmitter\nAsynchronous with async/await\n\n## Install\n```\nnpm i @antonbarinov/event-emitter-async\n```\n\n## Example\n```\nconst AsyncEventEmitter = require('@antonbarinov/event-emitter-async');\nconst aee = new AsyncEventEmitter();\n\nconst wait = (ms) => new Promise((resolve) => {\n    setTimeout(() => {\n        resolve(true);\n    }, ms);\n});\n\naee.on('test', async (arg1, arg2) => {\n    await wait(500);\n    console.log(1, arg1, arg2);\n});\n\naee.on('test', async (arg1, arg2) => {\n    await wait(500);\n    console.log(2, arg1, arg2);\n});\n\n// this subscription will be executed only once\naee.once('test', async (arg1, arg2) => {\n    await wait(500);\n    console.log(3, arg1, arg2);\n});\n\n(async () => {\n    console.log('--- event emitters has been started ---');\n    \n    // wait for all subscribed functions will be executed\n    await aee.emit('test', 'arg-1', 'arg-2');\n    \n    // wait for all subscribed functions will be executed\n    await aee.emit('test', 'arg-11', 'arg-22');\n    \n    console.log('--- event emitters has been finished ---');\n    console.log(aee.hasSubscribe('test'));\n    console.log(aee.hasSubscribe('test2'));\n})();\n```\n\nOutput:\n```\n--- event emitters has been started ---\n1 'arg-1' 'arg-2'\n2 'arg-1' 'arg-2'\n3 'arg-1' 'arg-2'\n1 'arg-11' 'arg-22'\n2 'arg-11' 'arg-22'\n--- event emitters has been finished ---\ntrue\nfalse\n```\n\n## Inheritance\n### Using `util.inherits`\n```\nconst AsyncEventEmitter = require('async-event-emitter');\nconst inherits = require('util').inherits;\n\nfunction Test() {\n    this.talk = () => {\n        console.log('Hello');\n    }\n}\ninherits(Test, AsyncEventEmitter);\n\nconst aee = new Test();\naee.talk();\nconst wait = (ms) => new Promise((resolve) => {\n    setTimeout(() => {\n        resolve(true);\n    }, ms);\n});\n\naee.on('test', async (arg1, arg2) => {\n    await wait(500);\n    console.log(1, arg1, arg2);\n});\n\naee.on('test', async (arg1, arg2) => {\n    await wait(500);\n    console.log(2, arg1, arg2);\n});\n\n// this subscription will be executed only once\naee.once('test', async (arg1, arg2) => {\n    await wait(500);\n    console.log(3, arg1, arg2);\n});\n\n(async () => {\n    console.log('--- event emitters has been started ---');\n\n    // wait for all subscribed functions will be executed\n    await aee.emit('test', 'arg-1', 'arg-2');\n\n    // wait for all subscribed functions will be executed\n    await aee.emit('test', 'arg-11', 'arg-22');\n\n    console.log('--- event emitters has been finished ---');\n})();\n```\n\n### Using `extends`\n```\nconst AsyncEventEmitter = require('async-event-emitter');\n\nclass Test extends AsyncEventEmitter {\n    myOn(eventName, func) {\n        this.on(eventName, func);\n    }\n\n    talk() {\n        console.log('Hello');\n    }\n}\n\nconst aee = new Test();\naee.talk();\nconst wait = (ms) => new Promise((resolve) => {\n    setTimeout(() => {\n        resolve(true);\n    }, ms);\n});\n\naee.myOn('test', async (arg1, arg2) => {\n    await wait(500);\n    console.log(1, arg1, arg2);\n});\n\naee.myOn('test', async (arg1, arg2) => {\n    await wait(500);\n    console.log(2, arg1, arg2);\n});\n\n// this subscription will be executed only once\naee.once('test', async (arg1, arg2) => {\n    await wait(500);\n    console.log(3, arg1, arg2);\n});\n\n(async () => {\n    console.log('--- event emitters has been started ---');\n\n    // wait for all subscribed functions will be executed\n    await aee.emit('test', 'arg-1', 'arg-2');\n\n    // wait for all subscribed functions will be executed\n    await aee.emit('test', 'arg-11', 'arg-22');\n\n    console.log('--- event emitters has been finished ---');\n})();\n``` ","readmeFilename":"README.md"}