找不到Elixir GenServer handle_cast函数

时间:2016-10-04 18:11:02

标签: elixir

我是Elixir的新手,所以这可能是非常简单但我无法找到答案。

所以我有一个像这样的简单GenServer:

defmodule BlobStorageActor do
  use GenServer

  def start_link do
    GenServer.start_link(__MODULE__, :ok, name: __MODULE__)  
  end

  def init(:ok) do
    {:ok, %{}}
  end

  def lookup(server, name) do
    GenServer.call(server, {:lookup, name})
  end

  def cp(pid, container, file_path) do
    GenServer.cast(pid, {:cp, container, file_path})
  end

  def handle_cast({:cp, container, file_path}, state) do
    %{body: containers} = ExAzure.request!(:list_containers)

    unless Enum.any?(containers, &( {:blob_container, container, _, _, _ } = &1)) do
      ExAzure.request(:create_container, [container])
    end

    ExAzure.request(:put_block_blob, [container, String.replace(file_path, " ", "_"), File.read!(file_path)])
  end
end

但是当我这样做时:

iex(53)> iex(4)> BlobStorageActor.cp(pid, "test", "Doxie 0008.pdf")
BlobStorageActor.cp(pid, "test", "Doxie 0008.pdf")
iex(53)> ** (FunctionClauseError) no function clause matching in GenServer.cast/2
iex(53)>     (elixir) lib/gen_server.ex:630: GenServer.cast({:ok, #PID<0.8023.0>}, {:cp, "test", "Doxie 0008.pdf"})
iex(53)> iex(4)> BlobStorageActor.cp(pid, "test", "Doxie 0008.pdf")
BlobStorageActor.cp(pid, "test", "Doxie 0008.pdf")
iex(53)> ** (FunctionClauseError) no function clause matching in GenServer.cast/2
iex(53)>     (elixir) lib/gen_server.ex:630: GenServer.cast({:ok, #PID<0.8023.0>}, {:cp, "test", "Doxie 0008.pdf"})

为什么我会收到此错误?

FunctionClauseError) no function clause matching in GenServer.cast/2

非常感谢任何帮助。

0 个答案:

没有答案