-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor connection management #328
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are still a bunch of todos that need resolving, but I like the approach taken here and don't have any major problems with it.
I haven't read changes made to devices, but I suspect that some care will be needed in them. I know that some of them are doing assertions on when properties are defined, as they get defined by init, but now that init resolves immediately, will those assumptions still be correct?
packages/timeline-state-resolver/src/service/ConnectionManager.ts
Outdated
Show resolved
Hide resolved
packages/timeline-state-resolver/src/service/ConnectionManager.ts
Outdated
Show resolved
Hide resolved
id: string, | ||
container: BaseRemoteDeviceIntegration<DeviceOptionsAnyInternal> | ||
) { | ||
const deviceOptions = this._config.get(id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
deviceOptions
could be a parameter, which would avoid needing this guard which might want to throw.
This could actually be a race condition, if setConnections
is called to remove a device between the start of createConnection
and here, then the config could disappear.
So maybe this guard is a good thing, and should be documented as such? or it should continue as normal, with it following the normal destroy route soon after
packages/timeline-state-resolver/src/service/ConnectionManager.ts
Outdated
Show resolved
Hide resolved
packages/timeline-state-resolver/src/service/ConnectionManager.ts
Outdated
Show resolved
Hide resolved
// trigger device init | ||
this._handleConnectionInitialisation(id, container).catch(() => { | ||
this.emit('error', 'Device ' + id + ' failed to initialise') | ||
this._connections.delete(id) // todo - this will cause device to be recreated next, which may cause a spiral? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is more cleanup needed?
This is discarding the thread, but the thread is probably still running at this point?
@@ -172,7 +167,7 @@ export class Conductor extends EventEmitter<ConductorEvents> { | |||
|
|||
private _options: ConductorOptions | |||
|
|||
private devices = new Map<string, BaseRemoteDeviceIntegration<DeviceOptionsBase<any>>>() | |||
public readonly connectionManager = new ConnectionManager() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this be public, or should select methods be re-exposed on this conductor?
7d9379c
to
a7ae873
Compare
This is pretty much ready and I'm leaving this in state I'm happy with but the unit tests appear to be very inconsistent for reasons that elude me so that will require some attention |
Type of Contribution
This is a Code improvement
Current Behavior
Library consumers must keep track of how devices are created and initialised and are responsible for managing this. In addition, a device may not finish initialising until the first connection has been made.
Proposed Behavior
A Connection is an instance of an Integration Implementation (previously known as devices, this terminology proved to be a bit confusing as "TSR devices" connected to actual devices). TSR shall be responsible for creating and initialising the connections based upon a config provided by the library user. An integration must ensure to not get stuck during the initialisation.
Discussion
I think there may actually some use for devices not being initialised immediately as it prevents the timeline states from being sent into the integration when it isn't ready yet. At the same time, integrations should handle this "disconnected" state gracefully. Perhaps some additional life cycle hooks are required (i.e. to rediff the state from empty)Status
This PR is part investigation and part implementation. Feedback is welcome at this time.