-
Notifications
You must be signed in to change notification settings - Fork 8
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
Allow custom app logic to trigger when a websocket connects/reconnects #75
Conversation
Signed-off-by: Peter Broadhurst <peter.broadhurst@kaleido.io>
Signed-off-by: Peter Broadhurst <peter.broadhurst@kaleido.io>
Signed-off-by: Peter Broadhurst <peter.broadhurst@kaleido.io>
async close(wait?: boolean): Promise<void> { | ||
const closedPromise = new Promise<void>(resolve => { | ||
this.closed = resolve; | ||
}); | ||
this.clearPingTimers(); | ||
if (this.socket) { |
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.
Rather than relying on the other "close" handler and dealing with callbacks back and forth, would it be possible to just add another handler here?
const closedPromise = new Promise<void>(resolve => this.socket.on('close', resolve));
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.
I'm not sure I can for the use case I'm fighting. Jest cannot handle any logging after a test completes, so what I need to know is that the existing callback that does logging has done it.
If I add another callback as you propose, then I'll be relying on the order of invocation of event handlers. Happy to do that if you'd prefer (I have written up the code for it ready to push, but I'll need to test it).
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.
Discussed in a message directly with @awrichar and deciding to merge.
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.
Looks alright to me - left one suggestion for possible simplification.
When using an ephemeral WebSocket to listen for completion of a FireFly action, you need to know the socket is connected before you submit the action. This isn't currently possible in the SDK.
It's also not possible to send custom commands over the WebSocket, or trigger other processing as a side-effect of a reconnect.
Also in unit tests in a framework like Jest, you cannot allow a test to write log statements after the test exits (see jestjs/jest#9324 (comment)).
This drives a requirement for a
close()
function that allows us to await the logging of the close, which is also included as an option in this PR.