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
def send(key: Box[String], msg: Any): Unit ={
Schedule.schedule(() => dispatchersFor(key) ! msg, 0 seconds)
}
so from outside I call it:
NamedCometListener.send(name, registerCometActor(this, name))
and if I understood Schedule correctly, the send method returns pretty
fast, not waiting for the result of
dispatchersFor(key)
But I still wonder if it would make for a useful feature, how would
you send the callback with your message in the future?
Thanks
Diego
> --
> Lift, the simply functional web framework: http://liftweb.net
> Code: http://github.com/lift
> Discussion: http://groups.google.com/group/liftweb
> Stuck? Help us help you:
> https://www.assembla.com/wiki/show/liftweb/Posting_example_code
--
Lift, the simply functional web framework: http://liftweb.net
Code: http://github.com/lift
Discussion: http://groups.google.com/group/liftweb
Stuck? Help us help you: https://www.assembla.com/wiki/show/liftweb/Posting_example_code
Uh, nice!
This is just what I was looking for. Thanks!
And added to the wiki
http://www.assembla.com/spaces/liftweb/wiki/Cool_Tips
Regards,
Diego