Skip to content

Instantly share code, notes, and snippets.

@slyphon
Last active November 20, 2015 16:55
Show Gist options
  • Save slyphon/9e977e5bb9ac741e99b5 to your computer and use it in GitHub Desktop.
Save slyphon/9e977e5bb9ac741e99b5 to your computer and use it in GitHub Desktop.
possible change to Memcache api
def cas(key: String, flags: Int, expiry: Time, value: Buf, casUnique: Buf): Future[JBoolean] = {
cas2(key, flags, expiry, value, casUnique).flatMap {
case Some(b) if b => JavaTrue
case Some(b) => JavaFalse
case None => JavaFalse
}
}
private[this] val SomeJTrue: Future[Option[JBoolean]] = Future.value(Some(true))
private[this] val SomeJFalse: Future[Option[JBoolean]] = Future.value(Some(false))
def cas2(key: String, flags: Int, expiry: Time, value: Buf, casUnique: Buf): Future[Option[JBoolean]] = {
try {
service(Cas(key, flags, expiry, value, casUnique)).flatMap {
case Stored() => SomeJTrue
case Exists() => SomeJFalse
case NotFound() => Future.None
case Error(e) => Future.exception(e)
case _ => Future.exception(new IllegalStateException)
}
} catch {
case t: IllegalArgumentException => Future.exception(new ClientError(t.getMessage))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment