« Return to Thread: does flowscript also support sht like setTimeout and setInterval ??

RE: does flowscript also support sht like setTimeout and setInterval ?? [SOLVED]

by Robby Pelssers-4 :: Rate this Message:

| View in Thread

Some parts of this message have been removed. Learn more about Nabble's security policy.

Works nice !!

 

function generateValuePropositions() {

   var id_collection = Collection.fromArray(getJson('getCommaSeparatedBasicTypeIds'));

   print('Starting generation of ' + id_collection.getLength() + ' value propositions!!');

   var index = 0;

   id_collection.forEach(

       /** we write the map and topics for each id **/

       function(id){

           //We delay invocation of the pipeline with 3 seconds

           setTimeout(

               function() {

                   print('Generating value proposition ' + id);

                   cocoon.processPipelineTo("write-map-and-topics/" + id, null, new Packages.java.io.ByteArrayOutputStream());

               }, index * 3000);

           index++;

       }

   );

   cocoon.sendPage('index.html');

}

 

From: Robby Pelssers [mailto:Robby.Pelssers@...]
Sent: Thursday, May 24, 2012 3:58 PM
To: dev@...
Subject: RE: does flowscript also support sht like setTimeout and setInterval ?? [SOLVED]

 

I found a nice article on stackoverflow showing how to create my own implementation in flowscript.  I will of course first need to thoroughly test it but it looks promising so far ;-)

 

var setTimeout,

    clearTimeout,

    setInterval,

    clearInterval;

 

(function () {

    var timer = new java.util.Timer();

    var counter = 1;

    var ids = {};

 

    setTimeout = function (fn,delay) {

        var id = counter++;

        ids[id] = new JavaAdapter(java.util.TimerTask,{run: fn});

        timer.schedule(ids[id],delay);

        return id;

    }

 

    clearTimeout = function (id) {

        ids[id].cancel();

        timer.purge();

        delete ids[id];

    }

 

    setInterval = function (fn,delay) {

        var id = counter++;

        ids[id] = new JavaAdapter(java.util.TimerTask,{run: fn});

        timer.schedule(ids[id],delay,delay);

        return id;

    }

 

    clearInterval = clearTimeout;

 

})();

From: Robby Pelssers [mailto:Robby.Pelssers@...]
Sent: Thursday, May 24, 2012 2:56 PM
To: dev@...
Subject: does flowscript also support sht like setTimeout and setInterval ??

 

Hi guys,

 

I was bulk processing DITA maps and topics from flowscript and noticed that following code is executed parallel.  So basically the cocoon.processPipelineTo returns immediately so it seems.  This results in max sessions reached to XMLDb and I run into an exception.  Just checking what is best way to put some delay in the execution.

 

function generateValuePropositions() {

   var id_collection = Collection.fromArray(getJson('getCommaSeparatedBasicTypeIds'));

   print('Starting generation of ' + id_collection.getLength() + ' value propositions!!');

   id_collection.forEach(

       /** we write the map and topics for each id **/

       function(id){

           cocoon.processPipelineTo("write-map-and-topics/" + id, null, new Packages.java.io.ByteArrayOutputStream());

       }

   );

}

 

Kind regards,

Robby

 « Return to Thread: does flowscript also support sht like setTimeout and setInterval ??