Spread.Sheets Documentation
AsyncFunction Constructor
GC.Spread.CalcEngine.Functions Namespace > AsyncFunction type : AsyncFunction Constructor
The name of the function.
The minimum number of arguments for the function.
The maximum number of arguments for the function.
The description of the function.
Represents an abstract base class for defining asynchronization functions.
Syntax
var instance = new GC.Spread.CalcEngine.Functions.AsyncFunction(name, minArgs, maxArgs, description);
function AsyncFunction( 
   name : string,
   minArgs : number,
   maxArgs : number,
   description : object
) : AsyncFunction;

Parameters

name
The name of the function.
minArgs
The minimum number of arguments for the function.
maxArgs
The maximum number of arguments for the function.
description
The description of the function.
Example
This example defines a custom function that extends the AsyncFunction class and creates a timeout to simulate the server side evaluate.
var asum = function () {}
//Define a class "ASUM" that extends AsyncFunction
asum.prototype = new GC.Spread.CalcEngine.Functions.AsyncFunction("ASUM", 1, 255);
//Set default value to "Loading..."
asum.prototype.defaultValue = function () { return "Loading..."; };
//Override the evaluateAsync function
asum.prototype.evaluateAsync = function (context) {
var args = arguments;
//Use a timeout to simulate the server side evaluate or use an ajax post
    setTimeout(function () {
//Evaluation logic
        var result = 0;
        for (var i = 0; i < args.length; i++) {
            result += args[i];
        }
        result *= 2;
//Set the async evaluate result to CalcEngine
        context.setAsyncResult(result);
    }, 2000);
}
//Or use Ajax post
$.ajax({
    //url: '@Url.Action("ASUM", "Home")',
    //type: "POST",
    //data: JSON.stringify(args),
    //contentType: "application/json,charset=UTF-8",
    //success: function (data) {
    //context.SetAsyncResult(data.result);
    //}
//});
//Add the ASUM function to spread and set the formula
activeSheet.addCustomFunction(new asum());
activeSheet.setValue(0, 0, 5);
activeSheet.setValue(0, 1, 15);
activeSheet.setFormula(1, 1, "ASUM(A1,B1)");
See Also

Reference

AsyncFunction type