Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Multiple async calls
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  8 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Meeraj Kunnumpurath  
View profile  
 More options Apr 25 2012, 3:08 pm
From: Meeraj Kunnumpurath <meeraj.kunnumpur...@asyska.com>
Date: Wed, 25 Apr 2012 20:08:33 +0100
Local: Wed, Apr 25 2012 3:08 pm
Subject: [2.0 - Scala] Multiple async calls

Hi,

What is the best way to use async HTTP in a controller that makes multiple
outbound WS calls such that the response is returned after all the calls
complete?

Kind regards
Meeraj


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Discussion subject changed to "[2.0 - Scala] Multiple async calls" by Pascal Voitot Dev
Pascal Voitot Dev  
View profile  
 More options Apr 25 2012, 4:06 pm
From: Pascal Voitot Dev <pascal.voitot....@gmail.com>
Date: Wed, 25 Apr 2012 22:06:17 +0200
Local: Wed, Apr 25 2012 4:06 pm
Subject: Re: [play-framework] [2.0 - Scala] Multiple async calls

You can use a wonderful feature from Promise:
Promise.sequence(List[Promise[A]]): Promise[List[A]]

You can provide it with a List (or any sequence) of promises and it returns
a Promise of List meaning it redeems all Promises before redeemining the
Promise[List].
So you can launch several WS calls in parallel and it will await for
responses in an asynchronous and non-blocking way...

A Promise can embed other promises etc... So you can build a tree of
promises etc...

interesting isn't it?

br
Pascal

On Wed, Apr 25, 2012 at 9:08 PM, Meeraj Kunnumpurath <


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Nourhan El Malahy  
View profile  
 More options Apr 25 2012, 4:08 pm
From: Nourhan El Malahy <nourhan.mal...@gmail.com>
Date: Wed, 25 Apr 2012 22:08:52 +0200
Local: Wed, Apr 25 2012 4:08 pm
Subject: Re: [play-framework] [2.0 - Scala] Multiple async calls

Guys, please how can I pop-up a message when the user clicks on a certain
button??

On Wed, Apr 25, 2012 at 10:06 PM, Pascal Voitot Dev <


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Pascal Voitot Dev  
View profile  
 More options Apr 25 2012, 4:37 pm
From: Pascal Voitot Dev <pascal.voitot....@gmail.com>
Date: Wed, 25 Apr 2012 22:37:44 +0200
Local: Wed, Apr 25 2012 4:37 pm
Subject: Re: [play-framework] [2.0 - Scala] Multiple async calls

please don't pollute another thread...
open a new thread if you have a specific question

thanks
Pascal

On Wed, Apr 25, 2012 at 10:08 PM, Nourhan El Malahy <


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Nourhan El Malahy  
View profile  
 More options Apr 25 2012, 4:46 pm
From: Nourhan El Malahy <nourhan.mal...@gmail.com>
Date: Wed, 25 Apr 2012 22:46:11 +0200
Local: Wed, Apr 25 2012 4:46 pm
Subject: Re: [play-framework] [2.0 - Scala] Multiple async calls

I'm Sorry, I didn't notice! I wrote it here by mistake!

On Wed, Apr 25, 2012 at 10:37 PM, Pascal Voitot Dev <


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Meeraj Kunnumpurath  
View profile  
 More options Apr 25 2012, 5:41 pm
From: Meeraj Kunnumpurath <meeraj.kunnumpur...@asyska.com>
Date: Wed, 25 Apr 2012 22:41:38 +0100
Local: Wed, Apr 25 2012 5:41 pm
Subject: Re: [play-framework] [2.0 - Scala] Multiple async calls

Thanks Pascal, I will have a look at that. Yes, I did see a passing
reference to this in the Play docco.

Regards
Meeraj

On Wed, Apr 25, 2012 at 9:06 PM, Pascal Voitot Dev <


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Meeraj Kunnumpurath  
View profile  
 More options Apr 26 2012, 5:42 pm
From: Meeraj Kunnumpurath <meeraj.kunnumpur...@asyska.com>
Date: Thu, 26 Apr 2012 22:42:11 +0100
Local: Thurs, Apr 26 2012 5:42 pm
Subject: Re: [play-framework] [2.0 - Scala] Multiple async calls

Hi Pascal,

Thanks for your suggestion, it works like a dream. I have the code below,
if it is of any help to anyone else.

def makeCall() = Action { implicit request =>

    def scheduleCalls(callIds : Seq[String], request : Request[AnyRef]) :
List[Promise[Response]] = {
        if (callIds.isEmpty) {
            return List()
        } else {
            val promise = WS.url("https://callUrl" + callIds.head).post("")
            promise :: scheduleCalls(callIds.tail, request)
        }
    }

    Async {
        val callIds = request.body.asFormUrlEncoded.get("callId")
        val promises = Promise.sequence(scheduleCalls(callIds, request))
        promises.map { response =>
            Ok("Ok")
        }
    }

}

Regards
Meeraj

On Wed, Apr 25, 2012 at 9:06 PM, Pascal Voitot Dev <


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Pascal Voitot Dev  
View profile  
 More options Apr 26 2012, 5:51 pm
From: Pascal Voitot Dev <pascal.voitot....@gmail.com>
Date: Thu, 26 Apr 2012 23:51:18 +0200
Local: Thurs, Apr 26 2012 5:51 pm
Subject: Re: [play-framework] [2.0 - Scala] Multiple async calls

One of the great features of Play2 ;)

You're welcome ;)

On Thu, Apr 26, 2012 at 11:42 PM, Meeraj Kunnumpurath <


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »