How do I use promises to make a db connection?

26 views
Skip to first unread message

jo...@ifany.org

unread,
Mar 7, 2013, 7:48:48 AM3/7/13
to dispatc...@googlegroups.com
Hi there,

I'm currently using dispatch to connect to Smugmugs json api for a website and caching the responses in a database (mongodb). Since I'm using promises for fetching data from smugmug's api, it makes sense to use Promises for encapsulating  a db-request in an asynchronous manner too, but I'm not sure how to go about doing this.

Are promises inherently linked to http requests and not suitable for anything else, or is there a way to 'lift' any function so it returns a promise?

pelagic

unread,
Mar 7, 2013, 7:55:26 PM3/7/13
to dispatc...@googlegroups.com
The idea of a promise isn't inherently coupled to an http requests but the specific implementation of promises in Dispatch might be. I took a quick look at the code and it looks like it is. akka has it's own implementation of promises that might be helpful.

http://doc.akka.io/api/akka/2.0/akka/dispatch/Promise.html

jo...@ifany.org

unread,
Mar 8, 2013, 8:32:03 AM3/8/13
to dispatc...@googlegroups.com
Thanks. I imagine using akka's promise would give me a bit of a headache if I wanted to introduce it in code that already uses dispatch's promise though, since I don't see how I would transform one to the other.

Adam Shannon

unread,
Mar 8, 2013, 8:44:17 AM3/8/13
to dispatc...@googlegroups.com
Scala 2.10 also has a Future implementation based on previous libraries futures.

http://www.scala-lang.org/api/current/index.html#scala.concurrent.Future

If you're on 2.10 you could use that for all your cases (and just wrap
dispatch's executions in it) until dispatch natively supports 2.10
futures.
> --
> You received this message because you are subscribed to the Google Groups
> "Dispatch" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to dispatch-scal...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>



--
Adam Shannon
Developer
University of Northern Iowa
Junior -- Computer Science & Mathematics
http://ashannon.us

Doug Tangren

unread,
Mar 8, 2013, 9:15:42 AM3/8/13
to dispatc...@googlegroups.com
On Fri, Mar 8, 2013 at 8:44 AM, Adam Shannon <ad...@ashannon.us> wrote:
Scala 2.10 also has a Future implementation based on previous libraries futures.

http://www.scala-lang.org/api/current/index.html#scala.concurrent.Future

If you're on 2.10 you could use that for all your cases (and just wrap
dispatch's executions in it) until dispatch natively supports 2.10
futures.


Dispatch has supported promises since the birth of reboot.  Dispatches promises implement the SIP for scalas futures ( since before 2.10.0 ) to be compatible and prepare for this new addition to the standard library. 

You do not need to add the additional ( and unnecessary dependency on something like akkas impl ) You won't gain much more than adding complexity to a simple problem.

Dispatches promises are not specific to HTTP requests. See the documentation

Reply all
Reply to author
Forward
0 new messages