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

Add Kino.tmp_dir/0 #344

Merged
merged 1 commit into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions lib/kino.ex
Original file line number Diff line number Diff line change
Expand Up @@ -516,4 +516,16 @@ defmodule Kino do
def interrupt!(variant, message) when variant in [:normal, :error] and is_binary(message) do
raise Kino.InterruptError, variant: variant, message: message
end

@doc """
Returns a temporary directory that gets removed when the runtime
terminates.
"""
@spec tmp_dir() :: String.t() | nil
def tmp_dir() do
case Kino.Bridge.get_tmp_dir() do
{:ok, path} -> path
{:error, _} -> nil
end
end
end
8 changes: 8 additions & 0 deletions lib/kino/bridge.ex
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,14 @@ defmodule Kino.Bridge do
with {:ok, reply} <- io_request(:livebook_get_app_info), do: reply
end

@doc """
Returns a temporary directory tied to the current runtime.
"""
@spec get_tmp_dir() :: {:ok, String.t()} | {:error, request_error() | :not_available}
def get_tmp_dir() do
with {:ok, reply} <- io_request(:livebook_get_tmp_dir), do: reply
end

@doc """
Checks if the caller is running within Livebook context (group leader).
"""
Expand Down
Loading