Current section
Files
Jump to
Current section
Files
src/radish@utils.erl
-module(radish@utils).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function]).
-export([prepare/1, execute/3, execute_blocking/3]).
-spec prepare(list(binary())) -> bitstring().
prepare(Parts) ->
_pipe = Parts,
_pipe@1 = gleam@list:map(_pipe, fun(Field@0) -> {bulk_string, Field@0} end),
_pipe@2 = {array, _pipe@1},
radish@encoder:encode(_pipe@2).
-spec execute(
gleam@erlang@process:subject(radish@client:message()),
bitstring(),
integer()
) -> {ok, radish@resp:value()} | {error, radish@error:error()}.
execute(Client, Cmd, Timeout) ->
gleam@result:then(
begin
_pipe = gleam@erlang@process:try_call(
Client,
fun(_capture) -> {command, Cmd, _capture, Timeout} end,
Timeout
),
gleam@result:replace_error(_pipe, actor_error)
end,
fun(Reply) -> gleam@result:then(Reply, fun(Reply@1) -> case Reply@1 of
{simple_error, Error} ->
{error, {server_error, Error}};
{bulk_error, Error} ->
{error, {server_error, Error}};
Value ->
{ok, Value}
end end) end
).
-spec execute_blocking(
gleam@erlang@process:subject(radish@client:message()),
bitstring(),
integer()
) -> {ok, radish@resp:value()} | {error, radish@error:error()}.
execute_blocking(Client, Cmd, Timeout) ->
My_subject = gleam@erlang@process:new_subject(),
gleam@erlang@process:send(
Client,
{blocking_command, Cmd, My_subject, Timeout}
),
_pipe = gleam_erlang_ffi:new_selector(),
_pipe@1 = gleam@erlang@process:selecting(
_pipe,
My_subject,
fun gleam@function:identity/1
),
_pipe@2 = gleam_erlang_ffi:select(_pipe@1),
(fun(Reply) -> case Reply of
{ok, {simple_error, Error}} ->
{error, {server_error, Error}};
{ok, {bulk_error, Error}} ->
{error, {server_error, Error}};
{ok, Value} ->
{ok, Value};
{error, Error@1} ->
{error, Error@1}
end end)(_pipe@2).