mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-17 23:33:12 +09:00
Refactor to keep handle to Instance in connection
Keep a handle to the Instance in the connection the host has to the instance so that methods can be called directly on the Instance. This simplifies logic that exists outside of the link system like the host shutting down all of its instances when it exits. Fixes validation error thrown on host shutdown with running instances.
This commit is contained in:
1 parent
82ed0adfc3
commit
56d3997675
2 files changed
+12
-18
No files matched your search
@@ -5,12 +5,11 @@ import type Instance from "./Instance";
|
||||
|
||||
export default class InstanceConnection extends lib.Link {
|
||||
plugins = new Map<string, string>();
|
||||
status: Instance["status"] = "stopped";
|
||||
|
||||
constructor(
|
||||
connector: lib.VirtualConnector,
|
||||
public host: Host,
|
||||
public instanceId: number
|
||||
public instance: Instance,
|
||||
) {
|
||||
super(connector);
|
||||
this.router = this.host.router;
|
||||
@@ -24,9 +23,8 @@ export default class InstanceConnection extends lib.Link {
|
||||
}
|
||||
|
||||
async snoopInstanceStatusChangedEvent(event: lib.InstanceStatusChangedEvent) {
|
||||
this.status = event.status as Instance["status"];
|
||||
if (this.status === "stopped") {
|
||||
this.host.instanceConnections.delete(this.instanceId);
|
||||
if (this.instance.status === "stopped") {
|
||||
this.host.instanceConnections.delete(this.instance.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user