Hi!
How do you determine the type of an answer from a cometactor?
Currently i am doing this:
var weekResults = scala.collection.mutable.Map[Tuple2[String, String],
LAFuture[Any]]()
...
weeks.weeks.map { w =>
weekResults(w) = apiHandler !< PropertyUpdater(id, Full(w._1),
Full(w._2), List("ga:visits", "ga:pageviews"))
}
...check that they are all satisfied ....
weekResults.map { w =>
val updaterResult =
w._2.asInstanceOf[LAFuture[PropertyUpdaterResult]].get
...
}
But i cant guarantee or really check that I got a
LAFuture[PropertyUpdaterResult there, can I?
Thanks in advance
Björn
--
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
Hope that helps
Diego
--
Diego Medina
Lift/Scala Developer
di...@fmpwizard.com
http://www.fmpwizard.com
On Sat, Feb 18, 2012 at 8:36 AM, bjoern...@googlemail.com <bjoern...@gmail.com> wrote:
> Thanks for your help.
> I though that the "satisfaction"-count should get periodically
> updated, but it isnt. Its just is "intialized" and than "gotcha".
On localSetup, you set the Map weekResults,
then on the first Tick you call
if (satisfied) {
which always returns true because it is defined as
private def satisfied:Boolean = {
weekResults.size == satisfaction
}
and
weekResults.size is always 100 because it is init'ed in localSetup to hold one LAFuture per value of weeks
Unfortunately I can't rework your sample project right now (not enough time, sorry), but I can give you a few pointers of what I would do, and that may help you get going.
1- I wouldn't setup so many thing on localSetup, It is better to tell the CometActor ( and any other actor for that matter), to do things based on messages. In your case, what action is the one that would trigger the work> is it a button click?, a file upload?, if it is a button, have the button send a message to the cometActor to start start the work.
2- I wouldn't use a LAFuture, this is very personal, and others may disagree, but I prefer to send messages to actors, let them do the work and then send me another message once they are done. In your case you have one actor, the CometActor, that can send a message to the LiftActor that does the APIHandler, as both are actors, they can send messages to each other.
3- How would you know when all 100 items have been processed?
I would have a second LiftActor that has a
private var cnt: Int = 0 //or choose something that makes sens for your app
and then, the flow would be:
1- CometActor sends a message to the LiftActor APIHandler to do work (regular message using !
2- APIHandler does its work and once done sends a message to the Counter LiftActor
3- Counter LiftActor knows what the total number should be, so it increases the internal counter and compares it to the final number, once those match, it sends a message to the comet actor with the final result, oh right, when it increases the counter, it can send the comet a message saying it just finished that one item.
I hope I understood what you are trying to do.
Regards
Diego
I dont know how to thank you. Your example code made me understand
much more of the way lift works. Thanks so much.
From your answer and the answers Diego provided a new question
raised.
I should use messages over LAFutures (they are not really a
replacement for another), shouldnt I?
Björn
--
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