Skip to content

Instantly share code, notes, and snippets.

@rystsov
Last active August 29, 2015 14:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rystsov/3e74988da0e09138a7ec to your computer and use it in GitHub Desktop.
Save rystsov/3e74988da0e09138a7ec to your computer and use it in GitHub Desktop.
def put(self, test, val, timeout):
due = now() + timeout
while due > now():
result = self._read_write_read(test, val, due)
if isinstance(result, NetworkError): continue
return result # OK or Conflict
return NetworkError()
def get(self, timeout):
return self.put(None, None, timeout)
def set_q(self, q):
return self._epic_change(
lambda state: state.q==q,
lambda state: state.q=q
)
def add_node(self, node):
return self._epic_change(
lambda state: node in state.nodes,
lambda state: state.nodes.append(node)
)
def rm_node(self, node):
return self._epic_change(
lambda state: node not in state.nodes,
lambda state: state.nodes.rm(node)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment