Lift Weekly Recap 1: Intro Times and the LAFuture

131 views
Skip to first unread message

Antonio Salazar Cardozo

unread,
Jan 8, 2014, 12:25:33 AM1/8/14
to lif...@googlegroups.com
Hey there folks! This year I'm going to be trying to give a weekly recap of what's going on in the Lift world,
with a particular eye on Lift 3 development. It's been going on relatively behind the scenes so far, and there
are goodies in there that haven't been shared widely enough. There's also been some forward development
and bug fixes in the 2.6 world, though those are more often mentioned here on the list. Either way, I wanted
to start putting together a weekly blurb that would give a quick recap of interesting developments in the
repository as well as, when I spot them, particularly interesting discoveries or tidbits from the Lift list and
elsewhere in the Lift-a-verse. If you have any ideas for things that might be mentioned in something like this,
drop me a line at savedfastcool AT gmail.com !

The shape of the recap will probably change over time. Super-long list posts like this aren't an ideal medium
IMO, but I didn't have a site to put this under yet, and I wanted to get it going instead of putting the site
and design and whatever else before the actual content that would be useful to folks.

For the first few weeks, I'll be trying to cover some of the stuff that's already gone into Lift 3 and Lift 2.6
(which is currently at 2.6-M1, doncha know). Today, we'll look at LAFuture.

Lift 3 and Lift 2.6-M1 add a set of methods to LAFuture to make them usable in for comprehensions.
In particular, LAFuture now implements map, flatMap, filter, and withFilter. This means you can now do
something like this:

val facebookUser: LAFuture[FbUser] = getFbUser
 
for {
user <- facebookUser
firstName <- user.firstName // LAFuture[String]
lastName <- user.lastName // LAFuture[String]
name = firstName + " " + lastName
avatar <- user.avatar // LAFuture[String]
if ! avatar.isEmpty
} yield {
"img [alt]" #> name &
"img [src]" #> avatar
}

(Provided, of course, that you have an API structured this way ;) )

Secondly, you can now specify the LAFuture's scheduler when creating the future. This is likely to be useful
in relatively few standard cases, but may be useful for testing. The default scheduler is LAScheduler, and
is what was always being used as the scheduler before.

LAFuture also now supports callbacks, installable by invoking onSuccess, onFail, and onComplete.
Before this, LAFuture was mostly used by invoking .get(<timeout>) on it in a thread fired up using
Schedule.schedule or something of the sort. Now you can set up an LAFuture, install a completion handler,
and let it do its thing. This can be particularly useful in comets, for example:

def lowPriority = {
case ShowName =>
facebookUser.flatMap(_.user.firstName).onSuccess(firstName => this ! PushName(firstName))
}

You can also chain these together:

def lowPriority = {
case ShowName =>
facebookUser.flatMap(_.user.firstName)
.onSuccess(firstName => this ! PushName(firstName))
.onFail(_ => partialUpdate(Call("facebookError()").cmd)
}
 
The LAFuture singleton now has a build function, which can be used to build a future around a
call-by-name value, say if you expect a user lookup operation to take a while:

val eventualDbUser = LAFuture.build(getLatestUser)
 
for {
dbUser <- eventualDbUser
fbUser <- dbUser.fbUser
...

Last but not least, the LAFuture singleton now also has an observeCreation function. This lets you
hook in and find out when a future is created on the current thread. This doesn't necessarily mean
the future will be satisfied on the current thread, but it has to be created on it. No clear examples
from me for this one, but if you come up with one please pass it on!

That's it for this time; next time, we'll have a quick look at some compatibility-breaking things in Lift 3
and the new Markdown support in Lift 2.6-M1/3.0.

Diego Medina

unread,
Jan 8, 2014, 12:32:34 AM1/8/14
to Lift
Awesome Antonio!

just one correction, the latest is 2.6-M2 :)

Also, how would you feel about posting these on http://lift.la/ ?

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
 
---
You received this message because you are subscribed to the Google Groups "Lift" group.
To unsubscribe from this group and stop receiving emails from it, send an email to liftweb+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
Diego Medina
Lift/Scala consultant
di...@fmpwizard.com
http://fmpwizard.telegr.am

Torsten Uhlmann

unread,
Jan 8, 2014, 2:10:06 AM1/8/14
to lif...@googlegroups.com
That is super great, thanks Antonio!

I too thought that these posts should not just vanish in the mailing list, but put up prominently in some blog, maybe also be mentioned on the lift web.net site- the same way the BREACH post is.

Thanks,
Torsten.

-- 
AGYNAMIX(R). Passionate Software.
Inh. Torsten Uhlmann | Buchenweg 5 | 09380 Thalheim
Phone:       +49 3721 273445
Fax:             +49 3721 273446
Web:           http://www.agynamix.de
Author of "Lift Web Applications How-To"

Peter Petersson

unread,
Jan 8, 2014, 2:16:24 AM1/8/14
to lif...@googlegroups.com
This is great Antonio !

best regards Peter Petersson


On 01/08/2014 06:25 AM, Antonio Salazar Cardozo wrote:
Hey there folks! This year I'm going to be trying to give a weekly recap of what's going on in the Lift world,
with a particular eye on Lift 3 development. It's been going on relatively behind the scenes so far, and there
are goodies in there that haven't been shared widely enough. There's also been some forward development
and bug fixes in the 2.6 world, though those are more often mentioned here on the list. Either way, I wanted
to start putting together a weekly blurb that would give a quick recap of interesting developments in the
repository as well as, when I spot them, particularly interesting discoveries or tidbits from the Lift list and
elsewhere in the Lift-a-verse. If you have any ideas for things that might be mentioned in something like this,
drop me a line at savedfastcool AT gmail.com !

The shape of the recap will probably change over time. Super-long list posts like this aren't an ideal medium
IMO, but I didn't have a site to put this under yet, and I wanted to get it going instead of putting the site
and design and whatever else before the actual content that would be useful to folks.

For the first few weeks, I'll be trying to cover some of the stuff that's already gone into Lift 3 and Lift 2.6
(which is currently at 2.6-M1, doncha know). Today, we'll look at LAFuture.

Lift 3 and Lift 2.6-M1 add a set of methods to LAFuture to make them usable in for comprehensions.
In particular, LAFuture now implements map, flatMap, filter, and withFilter. This means you can now do
something like this:

val facebookUser: LAFuture[FbUser] = getFbUser
 
for {< /div>

Viktor Hedefalk

unread,
Jan 8, 2014, 4:04:02 AM1/8/14
to liftweb
Great post! Thanks!

Tyler Weir

unread,
Jan 8, 2014, 8:54:45 AM1/8/14
to lif...@googlegroups.com
Excellent stuff!

gao...@gmail.com

unread,
Jan 8, 2014, 8:56:26 AM1/8/14
to lif...@googlegroups.com
Great!
Btw, could i translate this to Chinese and publish on my site?

Thanks
Chenguang He
-- 
gao...@gmail.com
Sent with Airmail

Antonio Salazar Cardozo

unread,
Jan 8, 2014, 10:58:11 AM1/8/14
to lif...@googlegroups.com
First things first, I totally screwed up the futures comet example; it should be:

def lowPriority = {
case ShowName =>
facebookUser.flatMap(_.user.firstName)
.onSuccess(firstName => this ! PushName(firstName))
.onFail(_ => this ! PushFacebookError)
}

This is important because I believe onFail and onSuccess will run on a thread that
is not necessarily the comet's thread, so running partialUpdate there could have some
pretty nasty consequences.

The cardinal rule of comets applies: if it comes from anywhere other than the comet itself,
don't call a method, send a message. I am a terrible person ;)

----
Diego—nyooo! Hahaha. For what it's worth, I got thrown by the draft release notes at https://github.com/lift/framework/releases . We'll need to do a little better on keeping those up to date. I've done a proper publish on those release notes so the M2 tarball now shows up above them (though there are no release notes for that).

----
Regarding the ultimate place we'll want to put these:

While I'm a committer and I'm kicking this off, I would like it to be independent of committers, since it relies on publicly available information and requires no write access to the Lift repository. In essence, I want to make it so that if at some point I need to hand it off, the person who it's handed off to need not be a committer. Contributions to this can be a relatively lightweight way to contribute to the project in the future, after it takes a little more concrete shape.

However, I do agree that it should be put up prominently on a blog, and I'm trying to figure out where exactly that will be. I may just set up a Github Pages or telegram thing for it to keep things simple. I also agree that we'll probably want to start linking to them on liftweb.net. All of that's on the to-do list, but as I mentioned I wanted to get it going rather than putting up a bunch of excuses that would stop me from doing it, and the mailing list seemed like a good first step :)

---
Chenguang—yes, please feel free to translate and post at will. Once I get some sort of site set up for doing this, having the translations up there as well (+ to other languages as available) would be really cool, too.

Thanks for the feedback!
Antonio
Reply all
Reply to author
Forward
0 new messages