{"name":"async-mqtt","version":"1.0.0","description":"Promise wrapper over MQTT.js","main":"index.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"repository":{"type":"git","url":"git+https://github.com/RangerMauve/async-mqtt.git"},"keywords":["mqtt","promise","async","publish","subscribe"],"author":{"name":"rangermauve"},"license":"MIT","bugs":{"url":"https://github.com/RangerMauve/async-mqtt/issues"},"homepage":"https://github.com/RangerMauve/async-mqtt#readme","dependencies":{"in-array":"^0.1.2","mqtt":"^2.3.1"},"devDependencies":{"mqtt-connection":"^3.0.0","tape":"^4.6.3"},"gitHead":"cb8f1c3ac904c113c1fa869e2302479e684a5992","_id":"async-mqtt@1.0.0","_shasum":"5c4f74e95b710ba16954eb3affb27e3e54c1468d","_from":".","_npmVersion":"3.8.7","_nodeVersion":"6.9.1","_npmUser":{"name":"rangermauve","email":"rangermauve@hotmail.com"},"maintainers":[{"name":"rangermauve","email":"rangermauve@hotmail.com"}],"dist":{"shasum":"5c4f74e95b710ba16954eb3affb27e3e54c1468d","tarball":"http://registry-npm.ywwl.com/async-mqtt/download/async-mqtt-1.0.0.tgz","integrity":"sha512-1cNC6YTz1RBKrvKFbWn8ZxDosWQDqmJ8fJyjj+1L06VRjCXUDb66yIycBtxkVQFQhris/Rsyc4/LYbCiYm7U+g==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIFp9iAS1z+PNLpVYBO4N+qQzPYLIG9R84fLtGaCz8SRzAiEAhRACwtPifyAJ2KjGLhGuRzAoE6x6efous5F/+5LRBus="}],"size":3497,"noattachment":false,"key":"/async-mqtt/-/async-mqtt-1.0.0.tgz"},"_npmOperationalInternal":{"host":"packages-18-east.internal.npmjs.com","tmp":"tmp/async-mqtt-1.0.0.tgz_1488146463598_0.0569747993722558"},"directories":{},"readme":"<h1 align=\"center\">async-mqtt</h1>\n<p align=\"center\">Promise wrapper over MQTT.js</p>\n<p align=\"center\">\n<a href=\"https://github.com/mqttjs/async-mqtt\">\n    <img alt=\"\" src=\"https://david-dm.org/mqttjs/async-mqtt.svg?style=flat-square\">\n</a>\n<a href=\"https://www.npmjs.com/package/async-mqtt\">\n    <img alt=\"\" src=\"https://img.shields.io/npm/dt/async-mqtt.svg?style=flat-square\">\n</a>\n<a href=\"https://www.npmjs.com/package/async-mqtt\">\n    <img alt=\"\" src=\"https://img.shields.io/npm/v/async-mqtt.svg?style=flat-square\">\n</a>\n<br>\n<a href=\"https://github.com/mqttjs/async-mqtt\">\n    <img alt=\"\" src=\"https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square\">\n</a>\n</p>\n\n**IMPORTANT: Make sure you handle rejections from returned promises because they won't crash the process**\n\n## API\n\nThe API is the same as [MQTT.js](https://github.com/mqttjs/MQTT.js#api), except the following functions now return promises instead of taking callbacks\n\n- publish\n- subscribe\n- unsubscribe\n- end\n\n\n## Example\n\n```javascript\nconst MQTT = require(\"async-mqtt\");\n\nconst client = MQTT.connect(\"tcp://somehost.com:1883\");\n\n// When passing async functions as event listeners, make sure to have a try catch block\n\nconst doStuff = async () => {\n\n\tconsole.log(\"Starting\");\n\ttry {\n\t\tawait client.publish(\"wow/so/cool\", \"It works!\");\n\t\t// This line doesn't run until the server responds to the publish\n\t\tawait client.end();\n\t\t// This line doesn't run until the client has disconnected without error\n\t\tconsole.log(\"Done\");\n\t} catch (e){\n\t\t// Do something about it!\n\t\tconsole.log(e.stack);\n\t\tprocess.exit();\n\t}\n}\n\nclient.on(\"connect\", doStuff);\n```\n\nAlternately you can skip the event listeners and get a promise.\n\n```js\nconst MQTT = require(\"async-mqtt\");\n\nrun()\n\nasync function run() {\n  const client = await MQTT.connectAsync(\"tcp://somehost.com:1883\")\n\n  console.log(\"Starting\");\n\ttry {\n\t\tawait client.publish(\"wow/so/cool\", \"It works!\");\n\t\t// This line doesn't run until the server responds to the publish\n\t\tawait client.end();\n\t\t// This line doesn't run until the client has disconnected without error\n\t\tconsole.log(\"Done\");\n\t} catch (e){\n\t\t// Do something about it!\n\t\tconsole.log(e.stack);\n\t\tprocess.exit();\n\t}\n}\n\n```\n\n## Wrapping existing client\n\n```javascript\nconst { AsyncClient } = require(\"async-mqtt\");\n\nconst client = getRegularMQTTClientFromSomewhere();\n\nconst asyncClient = new AsyncClient(client);\n\nasyncClient.publish(\"foo/bar\", \"baz\").then(() => {\n\tconsole.log(\"We async now\");\n\treturn asyncClient.end();\n});\n```\n","publish_time":1488146465258,"_cnpm_publish_time":1488146465258,"dist-tags":{"latest":"2.6.3"}}