Skip to content
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

feat(jupyter): add handling for comms #24250

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
44 changes: 33 additions & 11 deletions cli/js/40_jupyter.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,19 +402,42 @@ function enableJupyter() {
const { op_jupyter_broadcast, op_jupyter_comm_recv, op_jupyter_comm_open } =
core.ops;

function commOpen(commId, targetName) {
function comm(commId, targetName, msgCallback) {
op_jupyter_comm_open(commId, targetName);
}

async function commRecv(commId) {
const [data, buffers] = await op_jupyter_comm_recv(commId);
let closed = false;

// TODO(bartlomieju): return something, so we can close this comm.
(async () => {
while (true) {
const [data, buffers] = await op_jupyter_comm_recv(commId);

if (!data) {
closed = true;
break;
}

msgCallback?.({
...data,
buffers,
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow up on comment below, to mirror the send API

Suggested change
msgCallback?.({
...data,
buffers,
});
msgCallback?.(data, buffers);

}
})();

if (!data) {
return undefined;
}
return {
...data,
buffers,
close() {
if (closed) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also need to use an op_jupyter_ I assume, to clean up the mapping on the Rust side.

return;
}

closed = true;
},
send(data) {
return broadcast("comm_msg", {
comm_id: commId,
data: data,
});
},
bartlomieju marked this conversation as resolved.
Show resolved Hide resolved
};
}

Expand Down Expand Up @@ -493,8 +516,7 @@ function enableJupyter() {

globalThis.Deno.jupyter = {
broadcast,
commRecv,
commOpen,
comm,
display,
format,
md,
Expand Down
3 changes: 3 additions & 0 deletions cli/tools/jupyter/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ impl JupyterServer {
.send_iopub(messaging::Status::busy().as_child_of(parent))
.await?;

eprintln!("msg type on shell {}", msg.message_type());
match msg.content {
JupyterMessageContent::ExecuteRequest(execute_request) => {
self
Expand Down Expand Up @@ -375,6 +376,7 @@ impl JupyterServer {
// NOTE: This will belong on the stdin channel, not the shell channel
}
JupyterMessageContent::CommOpen(comm) => {
eprintln!("comm_open");
self
.comm_container
.create(&comm.comm_id.0, &comm.target_name, None);
Expand All @@ -390,6 +392,7 @@ impl JupyterServer {
// .await?;
}
JupyterMessageContent::CommInfoRequest(_req) => {
eprintln!("comm_open");
connection
.send(
messaging::CommInfoReply {
Expand Down
Loading