Last active
November 20, 2015 16:55
-
-
Save slyphon/9e977e5bb9ac741e99b5 to your computer and use it in GitHub Desktop.
possible change to Memcache api
This file contains 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
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