# GC.Spread.CalcEngine.Functions.AsyncFunction

## Content

# Class: AsyncFunction

[CalcEngine](../modules/GC.Spread.CalcEngine).[Functions](../modules/GC.Spread.CalcEngine.Functions).AsyncFunction

## Hierarchy

- [`Function`](GC.Spread.CalcEngine.Functions.Function)

  ↳ **`AsyncFunction`**

## Table of contents

### Constructors

- [constructor](GC.Spread.CalcEngine.Functions.AsyncFunction#constructor)

### Properties

- [maxArgs](GC.Spread.CalcEngine.Functions.AsyncFunction#maxargs)
- [minArgs](GC.Spread.CalcEngine.Functions.AsyncFunction#minargs)
- [name](GC.Spread.CalcEngine.Functions.AsyncFunction#name)
- [typeName](GC.Spread.CalcEngine.Functions.AsyncFunction#typename)

### Methods

- [acceptsArray](GC.Spread.CalcEngine.Functions.AsyncFunction#acceptsarray)
- [acceptsError](GC.Spread.CalcEngine.Functions.AsyncFunction#acceptserror)
- [acceptsMissingArgument](GC.Spread.CalcEngine.Functions.AsyncFunction#acceptsmissingargument)
- [acceptsReference](GC.Spread.CalcEngine.Functions.AsyncFunction#acceptsreference)
- [defaultValue](GC.Spread.CalcEngine.Functions.AsyncFunction#defaultvalue)
- [description](GC.Spread.CalcEngine.Functions.AsyncFunction#description)
- [evaluate](GC.Spread.CalcEngine.Functions.AsyncFunction#evaluate)
- [evaluateAsync](GC.Spread.CalcEngine.Functions.AsyncFunction#evaluateasync)
- [evaluateMode](GC.Spread.CalcEngine.Functions.AsyncFunction#evaluatemode)
- [findBranchArgument](GC.Spread.CalcEngine.Functions.AsyncFunction#findbranchargument)
- [findTestArgument](GC.Spread.CalcEngine.Functions.AsyncFunction#findtestargument)
- [interval](GC.Spread.CalcEngine.Functions.AsyncFunction#interval)
- [isBranch](GC.Spread.CalcEngine.Functions.AsyncFunction#isbranch)
- [isContextSensitive](GC.Spread.CalcEngine.Functions.AsyncFunction#iscontextsensitive)
- [isVolatile](GC.Spread.CalcEngine.Functions.AsyncFunction#isvolatile)

## Constructors

### <a id="constructor" name="constructor"></a> constructor

• **new AsyncFunction**(`name`, `minArgs?`, `maxArgs?`, `description?`)

Represents an abstract base class for defining asynchronous functions.
Asynchronous functions are typically used for operations that require server requests or other time-consuming tasks.

**`example`**
```javascript
class WeatherFunction extends GC.Spread.CalcEngine.Functions.AsyncFunction {
    constructor () {
        super('WEATHER', 0, 0, {
            description: "Get Weather",
            parameters: []
        });
    }
    evaluate (context) {
        setTimeout(function () { context.setAsyncResult('sunny'); }, 100); // Here use setTimeout to simulate the server call.
    }
}
spread.addCustomFunction(new WeatherFunction());
spread.getActiveSheet().setFormula(0, 0, '=WEATHER()');
```

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `name` | `string` | The name of the function. |
| `minArgs?` | `number` | - |
| `maxArgs?` | `number` | - |
| `description?` | [`IFunctionDescription`](../interfaces/GC.Spread.CalcEngine.Functions.IFunctionDescription) | - |

#### Overrides

[Function](GC.Spread.CalcEngine.Functions.Function).[constructor](GC.Spread.CalcEngine.Functions.Function#constructor)

## Properties

### <a id="maxargs" name="maxargs"></a> maxArgs

• **maxArgs**: `number`

Represents the maximum number of arguments for the function.

#### Inherited from

[Function](GC.Spread.CalcEngine.Functions.Function).[maxArgs](GC.Spread.CalcEngine.Functions.Function#maxargs)

___

### <a id="minargs" name="minargs"></a> minArgs

• **minArgs**: `number`

Represents the minimum number of arguments for the function.

#### Inherited from

[Function](GC.Spread.CalcEngine.Functions.Function).[minArgs](GC.Spread.CalcEngine.Functions.Function#minargs)

___

### <a id="name" name="name"></a> name

• **name**: `string`

Represents the name of the function.

#### Inherited from

[Function](GC.Spread.CalcEngine.Functions.Function).[name](GC.Spread.CalcEngine.Functions.Function#name)

___

### <a id="typename" name="typename"></a> typeName

• **typeName**: `string`

Represents the type name string used for supporting serialization.

#### Inherited from

[Function](GC.Spread.CalcEngine.Functions.Function).[typeName](GC.Spread.CalcEngine.Functions.Function#typename)

## Methods

### <a id="acceptsarray" name="acceptsarray"></a> acceptsArray

▸ **acceptsArray**(`argIndex`): `boolean`

Determines whether the function accepts array values for the specified argument.

**`function`**

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `argIndex` | `number` | Index of the argument. |

#### Returns

`boolean`

`true` if the function accepts array values for the specified argument; otherwise, `false`.

#### Inherited from

[Function](GC.Spread.CalcEngine.Functions.Function).[acceptsArray](GC.Spread.CalcEngine.Functions.Function#acceptsarray)

___

### <a id="acceptserror" name="acceptserror"></a> acceptsError

▸ **acceptsError**(`argIndex`): `boolean`

Indicates whether the function can process Error values.

**`function`**

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `argIndex` | `number` | Index of the argument. |

#### Returns

`boolean`

`true` if the function can process Error values for the specified argument; otherwise, `false`.

#### Inherited from

[Function](GC.Spread.CalcEngine.Functions.Function).[acceptsError](GC.Spread.CalcEngine.Functions.Function#acceptserror)

___

### <a id="acceptsmissingargument" name="acceptsmissingargument"></a> acceptsMissingArgument

▸ **acceptsMissingArgument**(`argIndex`): `boolean`

Indicates whether the Evaluate method can process missing arguments.

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `argIndex` | `number` | Index of the argument |

#### Returns

`boolean`

`true` if the Evaluate method can process missing arguments; otherwise, `false`.

#### Inherited from

[Function](GC.Spread.CalcEngine.Functions.Function).[acceptsMissingArgument](GC.Spread.CalcEngine.Functions.Function#acceptsmissingargument)

___

### <a id="acceptsreference" name="acceptsreference"></a> acceptsReference

▸ **acceptsReference**(`argIndex`): `boolean`

Determines whether the function accepts Reference values for the specified argument.

**`function`**

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `argIndex` | `number` | Index of the argument. |

#### Returns

`boolean`

`true` if the function accepts Reference values for the specified argument; otherwise, `false`.

#### Inherited from

[Function](GC.Spread.CalcEngine.Functions.Function).[acceptsReference](GC.Spread.CalcEngine.Functions.Function#acceptsreference)

___

### <a id="defaultvalue" name="defaultvalue"></a> defaultValue

▸ **defaultValue**(): `any`

Returns the default value of the evaluated function result before getting the async result.

#### Returns

`any`

The default value of the evaluated function result before getting the async result.

___

### <a id="description" name="description"></a> description

▸ **description**(): [`IFunctionDescription`](../interfaces/GC.Spread.CalcEngine.Functions.IFunctionDescription)

Returns the description of the function.

**`function`**

#### Returns

[`IFunctionDescription`](../interfaces/GC.Spread.CalcEngine.Functions.IFunctionDescription)

The description of the function.

#### Inherited from

[Function](GC.Spread.CalcEngine.Functions.Function).[description](GC.Spread.CalcEngine.Functions.Function#description)

___

### <a id="evaluate" name="evaluate"></a> evaluate

▸ **evaluate**(...`args`): `any`

Returns the result of the function applied to the arguments.

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `...args` | `any` | Arguments for the function evaluation |

#### Returns

`any`

The result of the function applied to the arguments.

#### Inherited from

[Function](GC.Spread.CalcEngine.Functions.Function).[evaluate](GC.Spread.CalcEngine.Functions.Function#evaluate)

___

### <a id="evaluateasync" name="evaluateasync"></a> evaluateAsync

▸ **evaluateAsync**(`context`, `args`): `any`

Returns the result of the function applied to the arguments.

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `context` | [`AsyncEvaluateContext`](GC.Spread.CalcEngine.AsyncEvaluateContext) | The evaluate context |
| `args` | `any` | Arguments for the function evaluation |

#### Returns

`any`

The result of the function applied to the arguments.

___

### <a id="evaluatemode" name="evaluatemode"></a> evaluateMode

▸ **evaluateMode**(): [`AsyncFunctionEvaluateMode`](../enums/GC.Spread.CalcEngine.Functions.AsyncFunctionEvaluateMode)

Decides how to re-calculate the formula.

#### Returns

[`AsyncFunctionEvaluateMode`](../enums/GC.Spread.CalcEngine.Functions.AsyncFunctionEvaluateMode)

The evaluate mode.

___

### <a id="findbranchargument" name="findbranchargument"></a> findBranchArgument

▸ **findBranchArgument**(`test`): `number`

Finds the branch argument.

**`example`**
```javascript
function EqualsFunction() {
    this.name = 'Equals';
    this.maxArgs = 3;
    this.minArgs = 3;
}
EqualsFunction.prototype = new GC.Spread.CalcEngine.Functions.Function();
EqualsFunction.prototype.evaluate = function(logicalTest, valueIfTrue, valueIfFalse) {
    return logicalTest ? valueIfTrue : valueIfFalse;
}
EqualsFunction.prototype.isBranch = function() {
    return true;
}
EqualsFunction.prototype.findTestArgument = function() {
    return 0;
}
EqualsFunction.prototype.findBranchArgument = function(logicalTestResult) {
    if (logicalTestResult === true) {
        return 1;
    }
    return 2;
}
var equalsFunction = new EqualsFunction();
var spread = GC.Spread.Sheets.findControl("ss") || GC.Spread.Sheets.findControl("sampleDiv");
spread.addCustomFunction(equalsFunction);
```

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `test` | `any` | The test. |

#### Returns

`number`

Indicates the index of the argument that would be treated as the branch condition.

#### Inherited from

[Function](GC.Spread.CalcEngine.Functions.Function).[findBranchArgument](GC.Spread.CalcEngine.Functions.Function#findbranchargument)

___

### <a id="findtestargument" name="findtestargument"></a> findTestArgument

▸ **findTestArgument**(): `number`

Finds the test argument when this function is branched.

**`example`**
```javascript
function EqualsFunction() {
    this.name = 'Equals';
    this.maxArgs = 3;
    this.minArgs = 3;
}
EqualsFunction.prototype = new GC.Spread.CalcEngine.Functions.Function();
EqualsFunction.prototype.evaluate = function(logicalTest, valueIfTrue, valueIfFalse) {
    return logicalTest ? valueIfTrue : valueIfFalse;
}
EqualsFunction.prototype.isBranch = function() {
    return true;
}
EqualsFunction.prototype.findTestArgument = function() {
    return 0;
}
EqualsFunction.prototype.findBranchArgument = function(logicalTestResult) {
    if (logicalTestResult === true) {
        return 1;
    }
    return 2;
}
var equalsFunction = new EqualsFunction();
var spread = GC.Spread.Sheets.findControl("ss") || GC.Spread.Sheets.findControl("sampleDiv");
spread.addCustomFunction(equalsFunction);
```

#### Returns

`number`

Indicates the index of the argument that would be treated as the test condition.

#### Inherited from

[Function](GC.Spread.CalcEngine.Functions.Function).[findTestArgument](GC.Spread.CalcEngine.Functions.Function#findtestargument)

___

### <a id="interval" name="interval"></a> interval

▸ **interval**(): `number`

Returns the interval.

#### Returns

`number`

The interval in milliseconds.

___

### <a id="isbranch" name="isbranch"></a> isBranch

▸ **isBranch**(): `boolean`

Gets a value that indicates whether this function is branched by arguments as conditional.
Used in conjunction with the findBranchArgument and findTestArgument.

**`example`**
```javascript
function EqualsFunction() {
    this.name = 'Equals';
    this.maxArgs = 3;
    this.minArgs = 3;
}
EqualsFunction.prototype = new GC.Spread.CalcEngine.Functions.Function();
EqualsFunction.prototype.evaluate = function(logicalTest, valueIfTrue, valueIfFalse) {
    return logicalTest ? valueIfTrue : valueIfFalse;
}
EqualsFunction.prototype.isBranch = function() {
    return true;
}
EqualsFunction.prototype.findTestArgument = function() {
    return 0;
}
EqualsFunction.prototype.findBranchArgument = function(logicalTestResult) {
    if (logicalTestResult === true) {
        return 1;
    }
    return 2;
}
var equalsFunction = new EqualsFunction();
var spread = GC.Spread.Sheets.findControl("ss") || GC.Spread.Sheets.findControl("sampleDiv");
spread.addCustomFunction(equalsFunction);
```

#### Returns

`boolean`

`true` if this instance is branched; otherwise, `false`.

#### Inherited from

[Function](GC.Spread.CalcEngine.Functions.Function).[isBranch](GC.Spread.CalcEngine.Functions.Function#isbranch)

___

### <a id="iscontextsensitive" name="iscontextsensitive"></a> isContextSensitive

▸ **isContextSensitive**(): `boolean`

Determines whether the evaluation of the function is dependent on the context in which the evaluation occurs.

**`example`**
```javascript
class ContextFunction extends GC.Spread.CalcEngine.Functions.Function {
    constructor () {
        super('CONTEXT', 0, 0);
    }
    isContextSensitive () {
        return true;
    }
    evaluate (context) {
        return context.row + "/" + context.column;
    }
}
spread.addCustomFunction(new ContextFunction());
spread.getActiveSheet().setFormula(0, 0, '=CONTEXT()');
```

#### Returns

`boolean`

`true` if the evaluation of the function is dependent on the context; otherwise, `false`.

#### Inherited from

[Function](GC.Spread.CalcEngine.Functions.Function).[isContextSensitive](GC.Spread.CalcEngine.Functions.Function#iscontextsensitive)

___

### <a id="isvolatile" name="isvolatile"></a> isVolatile

▸ **isVolatile**(): `boolean`

Determines whether the function is volatile while it is being evaluated.
The volatile function is re-evaluated when any cell in the workbook is changed.

**`example`**
```javascript
class RandColorFunction extends GC.Spread.CalcEngine.Functions.Function {
    constructor () {
        super('RANDCOLOR', 0, 0);
    }
    isVolatile () {
        return true;
    }
    evaluate () {
        return "#" + Math.floor(Math.random() * 16777215).toString(16);
    }
}
spread.addCustomFunction(new RandColorFunction());
spread.getActiveSheet().setFormula(0, 0, '=RANDCOLOR()');
```

#### Returns

`boolean`

`true` if the function is volatile; otherwise, `false`.

#### Inherited from

[Function](GC.Spread.CalcEngine.Functions.Function).[isVolatile](GC.Spread.CalcEngine.Functions.Function#isvolatile)
