From 2a81fe04d251209c2d0597ea14884c0f76f26bb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonatan=20K=C5=82osko?= Date: Wed, 27 Mar 2024 20:18:50 +0700 Subject: [PATCH] Add internal client monitoring --- lib/kino/bridge.ex | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/kino/bridge.ex b/lib/kino/bridge.ex index 2f3f478b..8c228bd0 100644 --- a/lib/kino/bridge.ex +++ b/lib/kino/bridge.ex @@ -210,6 +210,24 @@ defmodule Kino.Bridge do with {:ok, reply} <- io_request(:livebook_get_tmp_dir), do: reply end + @doc """ + Starts monitoring clients presence from the given process. + + The monitoring process receives the following messages: + + * `{:client_join, client_id}` + + * `{:client_leave, client_id}` + + When the monitor starts and there are already clients that joined, + the join message is going to be delivered for each of them right + away. + """ + @spec monitor_clients(pid()) :: :ok | {:error, request_error()} + def monitor_clients(pid) do + with {:ok, reply} <- io_request({:livebook_monitor_clients, pid}), do: reply + end + @doc """ Checks if the caller is running within Livebook context (group leader). """