Created
June 27, 2017 08:56
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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