CustomFunctions.StreamingInvocation interface

Provides information about the invocation of a streaming custom function. A streaming custom function can provide results which can change over time.

Call setResult() one or more times to provide the result instead of returning a result from the function.

Extends

Properties

setResult

Set the result for the custom function. May be called more than once.

Property Details

setResult

Set the result for the custom function. May be called more than once.

setResult: (value: ResultType | Error) => void;

Property Value

(value: ResultType | CustomFunctions.Error) => void

Remarks

[ API set: CustomFunctionsRuntime 1.1 ]

Examples

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/16-custom-functions/streaming-function.yaml

/** @CustomFunction 
 * @description Increments the cell with a given amount at a specified interval in milliseconds.
 * @param {number} amount - The amount to add to the cell value on each increment.
 * @param {number} interval - The time in milliseconds to wait before the next increment on the cell.
 * @param {CustomFunctions.StreamingInvocation<number>} invocation - Parameter to send results to Excel
 *     or respond to the user canceling the function.
 * @returns An incrementing value.
 */
function increment(amount: number, interval: number, invocation: CustomFunctions.StreamingInvocation<number>): void {
  let result = 0;
  const timer = setInterval(() => {
    result += amount;
    invocation.setResult(result);
  }, interval);

  invocation.onCanceled = () => {
    clearInterval(timer);
  }
}