How about:
def insert(user: User): Future[Unit] =
Future.successful(curatorManager.sharedLock(lockPath)) flatMap {
lock => if (lock.aquire(lockWaitDuration)) {
getIdByEmailAddress(user.emailAddress) map {
case null => throw ConflictException(s"Email ${user.emailAddress} already
exists")
case email =>
if (curatorManager.isConnected) {
//some more blocking/non-blocking methods here
Future.successful((): Unit)
} andThen { case _ => lock.release() }
} else throw StaleLockException(s"Zookeeper lock has expired. Connection
state is ${curatorManager.connectionState}")
}
}
On Fri, Mar 14, 2014 at 6:57 PM, Drew Kutcharian <[email protected]> wrote:
> Hey Guys,
>
> I have the following code https://gist.github.com/kutchar/9553112 which I
> would really love if I could get rid of the Await.result. Background, this
> is a method that tries to insert a user into Cassandra, using
> Zookeeper/Curator to lock the “table” so we can enforce uniqueness of the
> email address. All Cassandra operations are non-blocking (Netty backed) but
> the Curator locking operation is blocking.
>
> Thanks,
>
> Drew
>
> --
> >>>>>>>>>> Read the docs: http://akka.io/docs/
> >>>>>>>>>> Check the FAQ:
> http://doc.akka.io/docs/akka/current/additional/faq.html
> >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
> ---
> You received this message because you are subscribed to the Google Groups
> "Akka User List" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/akka-user.
> For more options, visit https://groups.google.com/d/optout.
>
--
Cheers,
√
*———————**Viktor Klang*
*Chief Architect - **Typesafe <http://www.typesafe.com/>*
Twitter: @viktorklang
--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ:
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.