Skip to content

Commit 48c7574

Browse files
authored
Merge pull request #32 from LI-NA/LI-NA-patch-2
Add reconnect method and test.
2 parents dbc0573 + 685ac95 commit 48c7574

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ class AsyncClient {
6161
})
6262
}
6363

64+
reconnect (...args) {
65+
return this._client.reconnect(...args);
66+
}
67+
6468
addListener (...args) {
6569
return this._client.addListener(...args);
6670
}

test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,26 @@ function runTests () {
131131
return client.end();
132132
});
133133
});
134+
135+
test('Calling reconnect after end should resolve once reconnect', t => {
136+
t.plan(2);
137+
138+
const client = AsyncMQTT.connect(SERVER_URL);
139+
140+
client.once('reconnect', () => {
141+
t.pass('Reconnect event occured');
142+
client.once('connect', () => {
143+
client.end();
144+
});
145+
});
146+
147+
client.once('connect', () => {
148+
client.end().then(() => {
149+
t.pass('End resolved');
150+
client.reconnect();
151+
});
152+
});
153+
});
134154
}
135155

136156
// Taken from MQTT.js tests

0 commit comments

Comments
 (0)