Do you have more specific questions, right now all I can say is "It works
like Futures work."
On Mar 14, 2014 9:19 PM, "Drew Kutcharian" <[email protected]> wrote:

> Thanks √iktor, getIdByEmailAddress returns a Future, so all the exceptions
> would already be wrapped in the Future. BTW, can you explain how this
> works? Mailny how does this approach avoid the problems of Await?
>
>
>
> On Mar 14, 2014, at 12:24 PM, √iktor Ҡlang <[email protected]> wrote:
>
> (assuming that getIdByEmailAddress(user.emailAddress) does not throw
> exceptions)
>
>
> On Fri, Mar 14, 2014 at 7:11 PM, √iktor Ҡlang <[email protected]>wrote:
>
>> 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
>>
>
>
>
> --
> 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.
>
>
>  --
> >>>>>>>>>> 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.
>

-- 
>>>>>>>>>>      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.

Reply via email to