Skip to content

Commit

Permalink
Added connectAsync docs
Browse files Browse the repository at this point in the history
  • Loading branch information
RangerMauve committed Aug 7, 2019
1 parent b937299 commit 2387c18
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,32 @@ const doStuff = async () => {
client.on("connect", doStuff);
```

Alternately you can skip the event listeners and get a promise.

```js
const MQTT = require("async-mqtt");

run()

async function run() {
const client = await MQTT.connectAsync("tcp://somehost.com:1883")

console.log("Starting");
try {
await client.publish("wow/so/cool", "It works!");
// This line doesn't run until the server responds to the publish
await client.end();
// This line doesn't run until the client has disconnected without error
console.log("Done");
} catch (e){
// Do something about it!
console.log(e.stack);
process.exit();
}
}

```

## Wrapping existing client

```javascript
Expand Down

0 comments on commit 2387c18

Please sign in to comment.