Skip to main content

Recursive array calls one after another through promise

 data = [1,2,3,4]
rules = [
                function(d){ return d.map(x => x * 2); },
                function(d){ return d.map(x => x * 2); }
            ]
recursive(0,rules,data);



function somelongrunningprocess(rule, data){
    var d = $.Deferred();
    setTimeout(function(){ var result = rule.call(undefined,data); d.resolve(result); },1000);
    return d;
}

function recursive(index, rules, data) {
            if(index < rules.length) {
                $.when(somelongrunningprocess(rules[index],data)).then(function(response){
                    console.log("after_rule",response);    
                    //recursive((index+1), rules, data);
                    recursive((index+1), rules, response);
                });            
            }
}

Comments

Popular posts from this blog

Reading Large JSON file through PHP Script

 <?php /* cat mexico.geojson | wc sed ':a;N;$!ba;s/\n/ /g' mexico.geojson  > mexico.geojson_out1 cat mexico.geojson_out1 | wc http://localhost/Utility/cord/largefile.php?filename=mexico.geojson_out1 sed -E 's/\{ "type": "FeatureCollection", "name": "mexico_administrative_osm_province_boundaries", "crs": \{ "type": "name", "properties": \{ "name": "urn:ogc:def:crs:OGC:1.3:CRS84" \} \}, "features": \[//g' ./mexico.geojson_out1  > mexico.geojson_out2 http://localhost/Utility/cord/largefile.php?filename=mexico.geojson_out2 sed -E 's/(\[|\{|\}|\])/ \1 /g' ./mexico.geojson_out2 > ./output/mexico.geojson_output http://localhost/Utility/cord/largefile.php?filename=output/mexico.geojson_output */ ini_set('max_execution_time', '500'); //300 seconds = 5 minutes ini_set('memory_limit', '1G');   //ini_set('max_execution...

Splitting Comma-Separated Values In MySQL

CREATE TABLE numbers (n INT);  INSERT INTO numbers VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9),     select id, substring_index( substring_index(email_recipients, ',', n), ',', -1 ) as email from dashboards join numbers on char_length(email_recipients) - char_length(replace(email_recipients, ',', '')) >= n - 1     Reference Site : https://www.sisense.com/blog/splitting-comma-separated-values-in-mysql/