-module(radish@client). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function]). -export([start/3]). -export_type([message/0]). -type message() :: shutdown | {command, bitstring(), gleam@erlang@process:subject({ok, bitstring()} | {error, mug:error()}), integer()}. -spec start(binary(), integer(), integer()) -> {ok, gleam@erlang@process:subject(message())} | {error, gleam@otp@actor:start_error()}. start(Host, Port, Timeout) -> gleam@result:then( begin _pipe = radish@tcp:connect(Host, Port, Timeout), gleam@result:replace_error( _pipe, {init_failed, {abnormal, <<"Unable to connect to Redis server"/utf8>>}} ) end, fun(Client) -> gleam@otp@actor:start(Client, fun(Msg, Client@1) -> case Msg of {command, Cmd, Reply_with, Msg_timeout} -> _pipe@1 = radish@tcp:execute( Client@1, Cmd, Msg_timeout ), gleam@otp@actor:send(Reply_with, _pipe@1), gleam@otp@actor:continue(Client@1); shutdown -> {stop, normal} end end) end ).