1

I'm going through the Elixir "Getting Started" tutorial, where the following code snippet is used:

test "removes buckets on exit", %{registry: registry} do
  KV.Registry.create(registry, "shopping")
  {:ok, bucket} = KV.Registry.lookup(registry, "shopping")
  Agent.stop(bucket)
  assert KV.Registry.lookup(registry, "shopping") == :error
end

Now, create/2 uses the cast operation whereas lookup uses call. So that means that an asynchronous call is executed and then immediately after that, a synchronous call which assumes the async action was performed successfully. Could timing issues result in the test failing when the code itself is correct, or is there some aspect of cast and call that I am missing?

4

1 に答える 1

3

GenServer はすべてのメッセージを順番に処理するため、lookup呼び出しは前のメッセージが完了するまでブロックされるcastため、タイミングの問題は発生しません。

于 2014-09-12T14:22:53.323 に答える