Aborting Long Processing Requests, JavaScript Programming Example of Aborting Long Processing Requests

Aborting Long Processing Requests

With the coding example below you will be able to abort long processing requests in Pivot. Don't hesitate to use programming samples by Webix to create high-performance web apps.

JS Code

var bad_dataset = [];
for (var i=1; i<200; i++)
  for (var j=1; j<100; j++)
    for (var k=1; k<2; k++) 
      bad_dataset.push({ a:i, b:j, c:k, d:i, e:j, f:k,  });

function runSlowTask(){
  $$("pivot").setStructure({
    "rows":["a"],
    "columns":["b", "d", "e", "f"],
    "values":[
      {"name":"c","text":"oil","operation":["min","sum"]}
    ],
    "filters":[]
  });
}

function runFastTask(){
  $$("pivot").setStructure({
    "rows":["a"],
    "columns":["b"],
    "values":[
      {"name":"c","text":"oil","operation":["min","sum"]}
    ],
    "filters":[]
  });
}

webix.debug_pivot = true;

webix.ui({
    margin:30, 
    rows: [
      {
        id:"pivot", view:"pivot",

        ping:function(start){
          var now = (new Date()).valueOf();
          //break if processing is longer than 3 seconds 
          if (now - start > 3*1000){
            alert("Too complex parameters, aborting");
            throw new Error("Aborting...");
          }
        },

        height:400, 
        data: bad_dataset,
        max: true
      },
      { cols:[
        { view:"button", value:"Build Pivot (fast)", inputWidth:200, align:"center", click: runFastTask },
        { view:"button", value:"Build Pivot (slow)", inputWidth:200, align:"center", click: runSlowTask }
      ]}
    ]
});