Skip to content

Instantly share code, notes, and snippets.

@myobie
Created June 27, 2017 08:56
Show Gist options
  • Select an option

  • Save myobie/f81a52f51b241786c3083fa8ebb99037 to your computer and use it in GitHub Desktop.

Select an option

Save myobie/f81a52f51b241786c3083fa8ebb99037 to your computer and use it in GitHub Desktop.
When creating a new key (node) in zookeeper, we check if we were the first to try and fail accordingly
defmodule ZK do
def create_znode(name) do
{:ok, pid} = ZNode.start_link(name)
if ZNode.first?(pid) do
{:ok, pid}
else
:ok = ZNode.delete(pid)
{:error, :already_exists}
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment