Skip to content

Commit

Permalink
Add Kino.tmp_dir/0 (#344)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonatanklosko authored Sep 14, 2023
1 parent 164378d commit 52047ad
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
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

0 comments on commit 52047ad

Please sign in to comment.