W3cubDocs

/Sass

LegacyAsyncFunction

LegacyAsyncFunction: ((this: LegacyPluginThis, done: ((result: LegacyValue) => void)) => void) | ((this: LegacyPluginThis, arg1: LegacyValue, done: LegacyAsyncFunctionDone) => void) | ((this: LegacyPluginThis, arg1: LegacyValue, arg2: LegacyValue, done: LegacyAsyncFunctionDone) => void) | ((this: LegacyPluginThis, arg1: LegacyValue, arg2: LegacyValue, arg3: LegacyValue, done: LegacyAsyncFunctionDone) => void) | ((this: LegacyPluginThis, arg1: LegacyValue, arg2: LegacyValue, arg3: LegacyValue, arg4: LegacyValue, done: LegacyAsyncFunctionDone) => void) | ((this: LegacyPluginThis, arg1: LegacyValue, arg2: LegacyValue, arg3: LegacyValue, arg4: LegacyValue, arg5: LegacyValue, done: LegacyAsyncFunctionDone) => void) | ((this: LegacyPluginThis, arg1: LegacyValue, arg2: LegacyValue, arg3: LegacyValue, arg4: LegacyValue, arg5: LegacyValue, arg6: LegacyValue, done: LegacyAsyncFunctionDone) => void) | ((this: LegacyPluginThis, args: [LegacyValue[], LegacyAsyncFunctionDone]) => void)

An asynchronous callback that implements a custom Sass function. This can be passed to functions, but only for render.

An asynchronous function must return undefined. Its final argument will always be a callback, which it should call with the result of the function once it's done running.

If this throws an error, Sass will treat that as the function failing with that error message.

sass.render({
file:'style.scss',
functions: {
"sum($arg1, $arg2)": (arg1, arg2, done) => {
if (!(arg1instanceofsass.types.Number)) {
thrownewError("$arg1: Expected a number");
} elseif (!(arg2instanceofsass.types.Number)) {
thrownewError("$arg2: Expected a number");
}
done(newsass.types.Number(arg1.getValue() + arg2.getValue()));
}
}
}, (result, error) => {
// ...
});

This is passed one argument for each argument that's declared in the signature that's passed to functions. If the signature takes arbitrary arguments, they're passed as a single argument list in the last argument before the callback.

Deprecated

This only works with the legacy render and renderSync APIs. Use CustomFunction with compile, compileString, compileAsync, and compileStringAsync instead.

© 2006–2025 the Sass team, and numerous contributors
Licensed under the MIT License.
https://sass-lang.com/documentation/js-api/types/LegacyAsyncFunction