-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Handle server disconnects / non-existing server (#14)
This PR improves the server connection experience / fixes some bugs: * Status bar item now shows `Deephaven: Connecting...` while a connection is being initialized (before it immediately showed as connected) * Status bar shows `Deephaven: Disconnected` if connection fails * If client disconnects due to server stopping or anything else that results in an Jsapi ide 'disconnect' event, the status bar will be updated to reflect the status * Updated status bar / quick pick menu icons ### Testing **Setup** If you clone this repo and run `npm install`, you should be able to `f5` to run the extension in debug mode. **Test Steps** * Start a DH server on `localhost:10000` * Connect to server in extension. Should see status bar "Connecting..." then "Connected" status (the connecting status may happen too quickly to really see it). * Kill server * Should see status bar item switch to disconnected * Attempt to re-connect to stopped server * Should see "Connecting..." status for longer this time and then a "Failed to initialize Deephaven API" toast. Status should say "Disconnected" fixes #4 fixes #5 fixes #6
- Loading branch information
Showing
10 changed files
with
145 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
export type EventListener = <TEvent>(event: TEvent) => void; | ||
export type UnsubscribeEventListener = () => void; | ||
|
||
/** | ||
* General purpose event dispatcher for events that can be subscribed to. | ||
*/ | ||
export class EventDispatcher<TEventName extends string> { | ||
private listeners: Map<string, Set<EventListener>> = new Map(); | ||
|
||
/** | ||
* Register an event listener for a given event name. | ||
* @param eventName The name of the event to listen for. | ||
* @param listener The event listener to register. | ||
* @returns A function that can be called to unsubscribe the event listener. | ||
*/ | ||
addEventListener = ( | ||
eventName: TEventName, | ||
listener: EventListener | ||
): UnsubscribeEventListener => { | ||
if (!this.listeners.has(eventName)) { | ||
this.listeners.set(eventName, new Set()); | ||
} | ||
|
||
this.listeners.get(eventName)?.add(listener); | ||
|
||
return () => { | ||
this.listeners.get(eventName)?.delete(listener); | ||
}; | ||
}; | ||
|
||
/** | ||
* Dispatch an event to all registered listeners. | ||
* @param eventName The name of the event to dispatch. | ||
* @param event The event to dispatch to all listeners | ||
*/ | ||
dispatchEvent = <TEvent>(eventName: TEventName, event?: TEvent): void => { | ||
this.listeners.get(eventName)?.forEach(listener => listener(event)); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters