How to convert a Twitter Future to Scala (2.10)/Akka Future

1,055 views
Skip to first unread message

Drew Kutcharian

unread,
Jan 12, 2013, 1:02:48 PM1/12/13
to akka...@googlegroups.com
Hey Guys,

Does anyone know what's the best way to convert (or wrap) a Twitter Future to a Scala 2.10 (Akka) Future? I'm using a Twitter library that returns Twitter Futures but I would like to convert them to Scala/Akka Future before passing them around in the rest of my code.

Thanks,

Drew

Derek Williams

unread,
Jan 12, 2013, 9:47:46 PM1/12/13
to Akka User List
I'm not really familiar with Twitter's library, but should be able to do something like this:

import scala.concurrent.{Future, Promise}
import com.twitter.util.{Future => TwitterFuture, Throw, Return}

def fromTwitter[A](twitterFuture: TwitterFuture[A]): Future[A] = {
  val promise = Promise[A]()
  twitterFuture respond {
    case Return(a) => promise success a
    case Throw(e)  => promise failure e
  }
  promise.future
}



--
>>>>>>>>>>      Read the docs: http://akka.io/docs/
>>>>>>>>>>      Check the FAQ: http://akka.io/faq/
>>>>>>>>>>      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 post to this group, send email to akka...@googlegroups.com.
To unsubscribe from this group, send email to akka-user+...@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user?hl=en.





--
Derek Williams

Andrew Headrick

unread,
Jan 14, 2013, 2:24:04 PM1/14/13
to akka...@googlegroups.com
Out of curiosity, which library are you using? I didn't know any of their libraries were 2.10 compatible yet.

-A

Drew Kutcharian

unread,
Jan 14, 2013, 3:10:10 PM1/14/13
to akka...@googlegroups.com
Thanks Derek. I'll give this a try.

Drew Kutcharian

unread,
Jan 14, 2013, 3:16:39 PM1/14/13
to akka...@googlegroups.com
I'm using libkestrel which I haven't yet tried to compile with 2.10 ;)


Evan Chan

unread,
Jan 14, 2013, 4:21:54 PM1/14/13
to akka...@googlegroups.com
This seems like it'd be great to document, so I added an Assembla ticket:

--
--
Evan Chan
Senior Software Engineer | 
e...@ooyala.com | (650) 996-4600
www.ooyala.com | blog | @ooyala

Jonas Bonér

unread,
Jan 15, 2013, 1:14:49 PM1/15/13
to akka...@googlegroups.com
I thought Twitter was moving to Scala Futures.
Jonas Bonér
Phone: +46 733 777 123
Home: http://jonasboner.com
Twitter: @jboner
Reply all
Reply to author
Forward
0 new messages