Skip to content

Commit f58ad37

Browse files
authored
Merge pull request #7 from arduino/cleanup-disconnect
Clean up the properties callbacks upon disconnect
2 parents 5dfe8f6 + 8f9deb5 commit f58ad37

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/index.js

+15
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,21 @@ const disconnect = id => new Promise((resolve, reject) => {
199199
}
200200

201201
client.disconnect();
202+
203+
// Remove property callbacks to allow resubscribing in a later connect()
204+
Object.keys(propertyCallback).forEach((topic) => {
205+
if (propertyCallback[topic]) {
206+
delete propertyCallback[topic];
207+
}
208+
});
209+
210+
// Clean up subscribed topics - a new connection might not need the same topics
211+
Object.keys(subscribedTopics).forEach((topic) => {
212+
if (subscribedTopics[topic]) {
213+
delete subscribedTopics[topic];
214+
}
215+
});
216+
202217
return resolve();
203218
});
204219

0 commit comments

Comments
 (0)