From f2ef3a8efbd9db9a0fdcdde91076fe708f6dffdc Mon Sep 17 00:00:00 2001 From: luin Date: Sat, 25 Jun 2016 18:22:27 +0800 Subject: [PATCH] feat: support quit cluster gracefully. Close #315 --- lib/cluster/index.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) 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 *