mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-16 23:30:41 +09:00
Add connected property to Slave and BaseConnection
Provide a convenience method for checking if the Master-Slave link is fully online via a .connected property. This is true if the link has been establised, is not in the dropped state, and not in the process of disconnecting.
This commit is contained in:
1 parent
679eec05bc
commit
33efb32aa9
3 files changed
+26
-6
No files matched your search
@@ -16,6 +16,7 @@ class BaseConnection extends libLink.Link {
|
||||
/** @member {module:master/src/WsServerConnector} module:master/src/BaseConnection#connector */
|
||||
super("master", target, connector);
|
||||
this._master = master;
|
||||
this._disconnecting = false;
|
||||
libLink.attachAllMessages(this);
|
||||
for (let masterPlugin of this._master.plugins.values()) {
|
||||
libPlugin.attachPluginMessages(this, masterPlugin);
|
||||
@@ -57,6 +58,7 @@ class BaseConnection extends libLink.Link {
|
||||
|
||||
async prepareDisconnectRequestHandler(message, request) {
|
||||
await libPlugin.invokeHook(this._master.plugins, "onPrepareSlaveDisconnect", this);
|
||||
this._disconnecting = true;
|
||||
this.connector.setClosing();
|
||||
return await super.prepareDisconnectRequestHandler(message, request);
|
||||
}
|
||||
@@ -72,6 +74,15 @@ class BaseConnection extends libLink.Link {
|
||||
|
||||
await this.connector.close(code, reason);
|
||||
}
|
||||
|
||||
/**
|
||||
* True if the link is connected, not in the dropped state and not in
|
||||
* the process of disconnecting.
|
||||
* @type {boolean}
|
||||
*/
|
||||
get connected() {
|
||||
return !this._disconnecting && this.connector.connected;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = BaseConnection;
|
||||
Reference in new issue
Block a user