Since you've tagged this as GWT i'm going to assume that your myFunction()
call is actaully doing something asynchronous, and that is why you can't simply wait for it to return. In this case you could do the following, although it's a bit messy:
final Iterator<Book> iter = books.iterator();
MyHandler handler = new MyHandler() {
@Override
public void onDone() {
if (iter.hasNext())
iter.next().myFunction(this);
}
};
//
// Start it going
//
if (iter.hasNext())
iter.next().myFunction(handler);
Note that this is now recursive, so if you have a lot of book objects the call stack is going to get quite deep, and this imposes an upper limit on the number of books before you overflow the stack (an upper limit that you can't reliably know, either) This is not such a problem if you're using a GWT service to trigger the callback, since the stack will have unwound due to the network stuff.
I don't mean to second-guess you here, but if you are calling an async gwt service then it's going to result in a lot of calls back and forth over the network. If this is the case then you could consider simply passing a list of Book objects to be processed to the service, instead of sending them one at a time.