From 65c5185b62f9d48f3046cc0397432fd11f911fbd Mon Sep 17 00:00:00 2001 From: John Wilger Date: Wed, 3 Jan 2024 17:51:26 -0800 Subject: [PATCH] Add a dynamic supervisor to the library --- lib/gpt_agent/supervisor.ex | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 lib/gpt_agent/supervisor.ex diff --git a/lib/gpt_agent/supervisor.ex b/lib/gpt_agent/supervisor.ex new file mode 100644 index 0000000..c1cde41 --- /dev/null +++ b/lib/gpt_agent/supervisor.ex @@ -0,0 +1,16 @@ +defmodule GptAgent.Supervisor do + @moduledoc """ + Manages the GptAgent processes, ensuring that there is only one process per thread-id. + """ + + use DynamicSupervisor + + def start_link(init_arg) do + DynamicSupervisor.start_link(__MODULE__, init_arg, name: __MODULE__) + end + + @impl DynamicSupervisor + def init(_init_arg) do + DynamicSupervisor.init(strategy: :one_for_one) + end +end