Skip to content

Commit

Permalink
Add elisp and js support for disconnecting from the server.
Browse files Browse the repository at this point in the history
The motivating use case is a nodejs server that wants to shut down but
blocks until the debugger disconnects.  This situation arises often
when a developer is using a tool like nodemon that automatically
restarts the server on every source file change.
  • Loading branch information
tmurph authored and NicolasPetton committed Feb 22, 2021
1 parent 338eb2e commit 0535461
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
8 changes: 8 additions & 0 deletions indium-client.el
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,14 @@ Once the client is connected, run the hook `indium-client-connected-hook'."
(lambda (&rest _)
(run-hooks 'indium-client-connected-hook))))

(defun indium-client-disconnect (&optional callback)
"Disconnect from the runtime, but do not stop the indium process.
When non-nil, evaluate CALLBACK with the result."
(indium-client-send `((type . "connection")
(payload . ((action . "disconnect"))))
callback))

(defun indium-client-evaluate (expression &optional frame callback)
"Evaluate EXPRESSION in the context of FRAME.
Expand Down
12 changes: 12 additions & 0 deletions server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,18 @@ Array of configurations.

No payload.

#### disconnect

*Request payload:*

| Key | Type or value | Description |
|:-------|:---------------|:------------|
| action | `"disconnect"` | Action type |

*Successful response payload:*

No payload.

#### close

*Request payload:*
Expand Down
11 changes: 11 additions & 0 deletions server/server/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ const connection = (data = {}, { success, error, stop }) => {
switch(data.action) {
case "connect":
return connect(data, { success, error });
case "disconnect":
return disconnect({ success, error });
case "close":
return stop();
default:
Expand Down Expand Up @@ -61,4 +63,13 @@ const connectToNode = async (options = {}, { success, error }) => {
success("Connected to Node!");
};

const disconnect = async ({ success, error }) => {
try {
await adapter.disconnect();
} catch(e) {
return error(e.message);
}
success("Disconnected");
};

module.exports = connection;

0 comments on commit 0535461

Please sign in to comment.