Vadim Gritsenko wrote:

Hi all,

I think I'm missing something... But according to my observations, continuations are not capturing current state of the local variables. Consider following snippet:

function test() {
   var k = [];
   for (var i = 0; i < 5; i++) {
       k[i] = capture();
       if (k[i] == undefined) {
           cocoon.log.debug("Continuation resumed; i = " + i);
           FOM_Cocoon.suicide();
       }
   }

   k[2]();
}

function capture() {
   return new Continuation();
}


Once executed, you might expect that it will print "Continuation resumed; i = 2". But instead, it prints "Continuation resumed; i = 5", which is last state of the local variable "i", not the state the variable had when continuation was captured. I guess continuation only captures


The issue described above, combined with woody forms, makes wizards impossible - you can't get to the previous wizard page, as position will always point to the last visited page, instead of the page of the continuation. Any suggestions?


What I suggested some time ago about this is to have some kind of ContinuationLocal variables, similar to what ThreadLocal are to threads. The idea is that an object shared by a number of continuation holds a value, but this value is different for each continuation.

This could be implemented by associating a Map to continuations. To be truly useful, however, setting the value of a ContinuationLocal must associate that value with the _next_ continuation that will be created.

Sylvain

--
Sylvain Wallez                                  Anyware Technologies
http://www.apache.org/~sylvain           http://www.anyware-tech.com
{ XML, Java, Cocoon, OpenSource }*{ Training, Consulting, Projects }
Orixo, the opensource XML business alliance  -  http://www.orixo.com




Reply via email to