Skip to content

Conversation

bartlomieju
Copy link
Member

No description provided.

bartlomieju and others added 4 commits June 18, 2024 23:42
Co-Authored-By: Trevor Manz <trevor.j.manz@gmail.com>
Co-Authored-By: Kyle Kelley <rgbkrk@gmail.com>
...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.

Co-authored-by: Trevor Manz <trevor.j.manz@gmail.com>
Signed-off-by: Bartek Iwańczuk <biwanczuk@gmail.com>
Comment on lines 420 to 423
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);

@manzt
Copy link
Contributor

manzt commented Jun 26, 2024

Bikeshedding the API... right now you still need to open the comm with broadcast separately ("comm_open") message.

let comm = await Deno.jupyter.commOpen(commId, {
  targetName: "jupyter.widgets",
  data: { /* anywidget stuff */ },
  metadata: { version: "2.1.0" },
});

// either only allow one callback or manage a set of them
comm.on((data, buffers) => {

});

comm.close();

comm.send(data, buffers);

or something more webby (e.g., EventTarget, AudioContext as inspo):

let comm = new Deno.jupyter.Comm(commId, {
  targetName: "jupyter.widgets",
  data: { /* anywidget stuff */ },
  metadata: { version: "2.1.0" },
});

comm.addEventListener("message", (event) => {
  let { data, buffers } = event.detail;
});

comm.removeEventListener("message", /* function */ );

comm.dispatchEvent(
  new CustomEvent("message", { detail: { data, buffers } })
  // or something custom - new Deno.jupyter.MessageEvent(data, { buffers });
);

comm.close();

the latter would be easy to extend for other messages https://jupyter-client.readthedocs.io/en/latest/messaging.html#tearing-down-comms:

comm.addEventListener("close", () => {
  // front-end closed cleanup stuff
});

let Some(comm) = maybe_comm else {
return (serde_json::Value::Null, vec![]);
};
comm.receiver.resubscribe()
Copy link
Member Author

Choose a reason for hiding this comment

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

@manzt @rgbkrk if we go with EventListener approach for a comm then we can expect more than one consumer of the "comm". That means we need to use tokio::sync::broadcast channel which is buffered. We can go with a rather big number for the buffer like 1024 or 65536. If we expect only a single consumer then we could use an mpsc channel that is unbounded. Which one should we go with?

Copy link
Contributor

Choose a reason for hiding this comment

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

For widgets, I think it will basically only be one comm listener. There is new comm created for each new widget instance.

bartlomieju added a commit that referenced this pull request Jul 2, 2024
Moves the ZeroMQ messaging server to a separate thread.

This will allow to run blocking JS code and maintain communication
with the notebook frontend.

Towards #23592
Towards #24250
Closes #23617
@bartlomieju
Copy link
Member Author

@manzt quick question

let comm = await Deno.jupyter.commOpen(commId, {
  targetName: "jupyter.widgets",
  data: { /* anywidget stuff */ },
  metadata: { version: "2.1.0" },
});

What is metadata supposed to do when opening the comm? According to https://jupyter-client.readthedocs.io/en/latest/messaging.html#opening-a-comm it's not used.

@manzt
Copy link
Contributor

manzt commented Jul 6, 2024

What is metadata supposed to do when opening the comm? According to jupyter-client.readthedocs.io/en/latest/messaging.html it's not used.

The metadata is required for "comm_open" for with jupyter.widget target. With this PR I can successfully communicate with the anywidget frontend, sending frontend ESM via comms with updates.

The docs say it's often not used, but in the case of the jupyter.widgets front-end target it is required (there is an exception in the frontend when it's missing). So it's metadata that's specific to the targetName, and not necessary for opening any comm I assume.

zebreus pushed a commit to zebreus/deno that referenced this pull request Jul 8, 2024
…24373)

Moves the ZeroMQ messaging server to a separate thread.

This will allow to run blocking JS code and maintain communication
with the notebook frontend.

Towards denoland#23592
Towards denoland#24250
Closes denoland#23617
@bartlomieju bartlomieju added this to the 2.1.0 milestone Sep 12, 2024
@bartlomieju bartlomieju modified the milestones: 2.1.0, 2.2.0 Nov 12, 2024
@bartlomieju bartlomieju removed this from the 2.2.0 milestone Jan 30, 2025
@dsherret dsherret marked this pull request as draft April 15, 2025 18:57
@ry
Copy link
Member

ry commented May 9, 2025

reopen when it's ready - closing because old

@ry ry closed this May 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants