cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Igor Bukanov ...@igor.fastmail.fm>
Subject Re: Switching rhino implementation
Date Tue, 02 Nov 2004 12:31:23 GMT
 > Leszek Gawron wrote:
 > From what I see in this mail new implementation still allows for
 > cleanup code after continuation has been created but does not allow for
 > automatic resource fetching ( catch( continue ) ).
 >
 > <quote>
 > var pool = ...;
 >
 > function someFunction() {
 >
 >       var conn = pool.getConnection();
 >       ...
 >
 >       catch (break) {
 >           conn.close();
 >           conn = null;
 >       }
 >
 >       catch (continue) {
 >           conn = pool.getConnection();
 >       }
 > }
 >
 > with the patch would like:
 >
 > var pool = ...;
 >
 > function someFunction() {
 >
 >       var conn = null;
 >       try {
 >           if (conn == null) {
 >               conn = pool.getConnection();
 >           }
 >           ...
 >       } finally {
 >           conn.close();
 >           conn = null;
 >       }
 > }
 > </quote>
 >
 > so now you have to fetch the connection yourself each time the 
continuation is
 > resumed right?

But you have to "fetch the connection" each time even with old code! The 
new implementation has the same number of lines and avoids duplication 
of calls to pool.getConnection() so it is hard to see why it could be 
any significantly worse.

 > Is there any chance for porting that feature into new
 > implementation?

Not with the old syntax: the problem with the catch extensions is that 
its behavior is undefined if an exception is thrown or a continuation is 
caught/restored inside such catch block. "Undefined" here means that 
depending on the situation it would either throw NullPointerException 
and friends or go to the infinite loop.

A better idea IMO is to allow to write something like:

try initially {
	var conn = pool.getConnection();
} try {
	use connection
} finally {
	conn.close();
}

where "try initially" would always be executed on continuation restore. 
Alternative syntax suggestions are welcome but keep in mind that they 
should be 100% compatible with the current JS.

But again, there are too many cases to worry about on the runtime part 
=> takes time to implement.

Regards, Igor

Mime
View raw message