Message from discussion
LiftActor future with callback?
Received: by 10.52.32.66 with SMTP id g2mr9015652vdi.5.1334540533415;
Sun, 15 Apr 2012 18:42:13 -0700 (PDT)
X-BeenThere: liftweb@googlegroups.com
Received: by 10.52.67.103 with SMTP id m7ls2250170vdt.3.gmail; Sun, 15 Apr
2012 18:42:07 -0700 (PDT)
Received: by 10.52.72.72 with SMTP id b8mr623393vdv.19.1334540527469;
Sun, 15 Apr 2012 18:42:07 -0700 (PDT)
Date: Sun, 15 Apr 2012 18:42:06 -0700 (PDT)
From: Antonio Salazar Cardozo <savedfastc...@gmail.com>
To: liftweb@googlegroups.com
Message-ID: <6713618.3105.1334540526925.JavaMail.geo-discussion-forums@vbiz13>
In-Reply-To: <CAE-RkXh+cQOSdh92FrxtYt7tkx_XhHeZaUG_Peo1Uk2k2pokqQ@mail.gmail.com>
References: <CAE-RkXh+cQOSdh92FrxtYt7tkx_XhHeZaUG_Peo1Uk2k2pokqQ@mail.gmail.com>
Subject: Re: LiftActor future with callback?
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="----=_Part_3103_15705408.1334540526924"
------=_Part_3103_15705408.1334540526924
Content-Type: multipart/alternative;
boundary="----=_Part_3104_21639983.1334540526924"
------=_Part_3104_21639983.1334540526924
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Is there a reason you can't just bundle the callback with the message? Or
do the futures have specific synchronization semantics?
Thanks,
Antonio
On Saturday, April 14, 2012 3:48:35 PM UTC-4, fmpwizard wrote:
>
> Hi,
>
> Is there a way to have a callback function send to a LiftActor, along
> with a message, so that when the LiftActor is done processing the
> message, it will execute my callback?
> What I'm looking for is something similar (or exactly) like Twitter's
> finagle Future with callback.
> https://github.com/twitter/finagle#Future%20Callbacks
>
> As an example:
>
> val request: HttpRequest = new DefaultHttpRequest(HTTP_1_1, GET, "/")
> val responseFuture: Future[HttpResponse] = client(request)
> responseFuture onSuccess { responseFuture =>
> println(responseFuture)
> }
>
> so if responseFuture executes and all goes well, the println will be
> called.
>
> My real use case is this:
>
> On my snippet I send a message to an actor A, this message has a key
> form a key-> value map.
> The value is a reference to another LiftActor B, so once A selects the
> actor B, it needs to send B another message, so B can do its job.
>
> One limitation I have is that I cannot modify the final message I send
> to B, if I could I would just do something like:
>
> case class ComposedMessage(key: String, msg: String)
>
> So, if we had a Future with Callback in Lift I imagine I could do:
>
> case class Message(msg: String)
> case class Key(key: String)
>
> val actorResponseFuture= LiftActorA !< Key("123")
> actorResponseFuture onSuccess { responseActor =>
> responseActor ! Message("Do this job")
> }
>
>
> So I guess my question now is two fold:
>
> 1- Can this be done today?
> 2- If not, would it be useful to add such a feature?
>
> And just in case it wasn't clear, I'm trying to do it this way so that
> the thread my snippet is in does not block while all that processing
> is happening.
>
> Thanks
>
> Diego
>
>
> --
> Diego Medina
> Lift/Scala Developer
> di...@fmpwizard.com
> http://www.fmpwizard.com
>
>
------=_Part_3104_21639983.1334540526924
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable
Is there a reason you can't just bundle the callback with the message? Or d=
o the futures have specific synchronization semantics?<div>Thanks,</div><di=
v>Antonio<br><br>On Saturday, April 14, 2012 3:48:35 PM UTC-4, fmpwizard wr=
ote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex=
;border-left: 1px #ccc solid;padding-left: 1ex;">Hi,<p>Is there a way to ha=
ve a callback function send to a LiftActor, along<br>with a message, so tha=
t when the LiftActor is done processing the<br>message, it will execute my =
callback?<br>What I'm looking for is something similar (or exactly) like Tw=
itter's<br>finagle Future with callback.<br><a href=3D"https://github.com/t=
witter/finagle#Future%20Callbacks" target=3D"_blank">https://github.com/twi=
tter/<wbr>finagle#Future%20Callbacks</a></p><p>As an example:</p><p>val req=
uest: HttpRequest =3D new DefaultHttpRequest(HTTP_1_1, GET, "/")<br>val res=
ponseFuture: Future[HttpResponse] =3D client(request)<br>responseFuture onS=
uccess { responseFuture =3D><br> println(responseFuture)<br>}</p><=
p>so if responseFuture executes and all goes well, the println will be call=
ed.</p><p>My real use case is this:</p><p>On my snippet I send a message to=
an actor A, this message has a key<br>form a key-> value map.<br>The va=
lue is a reference to another LiftActor B, so once A selects the<br>actor B=
, it needs to send B another message, so B can do its job.</p><p>One limita=
tion I have is that I cannot modify the final message I send<br>to B, if I =
could I would just do something like:</p><p>case class ComposedMessage(key:=
String, msg: String)</p><p>So, if we had a Future with Callback in Lift I =
imagine I could do:</p><p>case class Message(msg: String)<br>case class Key=
(key: String)</p><p>val actorResponseFuture=3D LiftActorA !< Key("123")<=
br>actorResponseFuture onSuccess { responseActor =3D><br> response=
Actor ! Message("Do this job")<br>}</p><p><br>So I guess my question now is=
two fold:</p><p>1- Can this be done today?<br>2- If not, would it be usefu=
l to add such a feature?</p><p>And just in case it wasn't clear, I'm trying=
to do it this way so that<br>the thread my snippet is in does not block wh=
ile all that processing<br>is happening.</p><p>Thanks</p><p> Diego</p=
><p><br>-- <br>Diego Medina<br>Lift/Scala Developer<br><a href=3D"mailto:di=
e...@fmpwizard.com" target=3D"_blank">di...@fmpwizard.com</a><br><a href=3D"=
http://www.fmpwizard.com" target=3D"_blank">http://www.fmpwizard.com</a><br=
></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p>=
<p></p><p></p><p></p><p></p><p></p><p></p></blockquote></div>
------=_Part_3104_21639983.1334540526924--
------=_Part_3103_15705408.1334540526924--