diff --git a/lib/cluster/index.js b/lib/cluster/index.js index e1bd887f4..9de52e9d6 100644 --- a/lib/cluster/index.js +++ b/lib/cluster/index.js @@ -208,6 +208,27 @@ Cluster.prototype.disconnect = function (reconnect) { this.connectionPool.reset([]); }; +/** + * Quit the cluster gracefully. + * + * @return {Promise} + * @public + */ +Cluster.prototype.quit = function (reconnect) { + this.setStatus('disconnecting'); + + if (!reconnect) { + this.manuallyClosing = true; + } + if (this.reconnectTimeout) { + clearTimeout(this.reconnectTimeout); + this.reconnectTimeout = null; + } + return this.nodes().map(function (node) { + return node.quit(); + }); +}; + /** * Get nodes with the specified role *