Elixir語言中 GenServer.reply
相關用法介紹如下。
用法:
reply(client, reply)
@spec reply(from(), term()) :: :ok
回複客戶。
當無法在
的返回值中指定回複時,此函數可用於顯式向調用 handle_call/3
或 call/3
的客戶端發送回複。multi_call/4
client
必須是
回調接受的 handle_call/3
from
參數(第二個參數)。 reply
是一個任意術語,它將作為調用的返回值返回給客戶端。
請注意,可以從任何進程調用
,而不僅僅是最初接收調用的GenServer(隻要GenServer以某種方式傳達reply/2
from
參數)。
此函數始終返回 :ok
。
例子
def handle_call(:reply_in_one_second, from, state) do
Process.send_after(self(), {:reply, from}, 1_000)
{:noreply, state}
end
def handle_info({:reply, from}, state) do
GenServer.reply(from, :one_second_has_passed)
{:noreply, state}
end
相關用法
- Elixir GenServer.multi_call用法及代碼示例
- Elixir GenServer.whereis用法及代碼示例
- Elixir GenServer用法及代碼示例
- Elixir StringIO.flush用法及代碼示例
- Elixir Calendar.ISO.date_to_string用法及代碼示例
- Elixir Enum.unzip用法及代碼示例
- Elixir Date.add用法及代碼示例
- Elixir Keyword.get用法及代碼示例
- Elixir Stream用法及代碼示例
- Elixir Registry.count_match用法及代碼示例
- Elixir List.keyfind!用法及代碼示例
- Elixir URI.decode用法及代碼示例
- Elixir Integer.pow用法及代碼示例
- Elixir NaiveDateTime用法及代碼示例
- Elixir Enum.min_max用法及代碼示例
- Elixir Path.basename用法及代碼示例
- Elixir Code.prepend_path用法及代碼示例
- Elixir Calendar.ISO.time_to_string用法及代碼示例
- Elixir Bitwise.~~~expr用法及代碼示例
- Elixir Kernel.SpecialForms.case用法及代碼示例
- Elixir String.contains?用法及代碼示例
- Elixir Map.keys用法及代碼示例
- Elixir Version用法及代碼示例
- Elixir Kernel.round用法及代碼示例
- Elixir Kernel.left / right用法及代碼示例
注:本文由純淨天空篩選整理自elixir-lang.org大神的英文原創作品 GenServer.reply(client, reply)。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。