语法
¥Syntax
@async
概述
¥Overview
@async
标记表示函数是 asynchronous,这意味着它是使用语法 async function foo() {}
声明的。请勿将此标记用于其他类型的异步函数,例如提供回调的函数。此标签在 JSDoc 3.5.0 及更高版本中可用。
¥The @async
tag indicates that a function is asynchronous, meaning that it
was declared using the syntax async function foo() {}
. Do not use this tag for other types of
asynchronous functions, such as functions that provide a callback. This tag is available in JSDoc
3.5.0 and later.
一般来说,你不需要使用这个标签,因为 JSDoc 会自动检测异步函数并在生成的文档中识别它们。但是,如果你正在为代码中未出现的异步函数编写虚拟注释,则可以使用此标记告诉 JSDoc 该函数是异步的。
¥In general, you do not need to use this tag, because JSDoc automatically detects asynchronous functions and identifies them in the generated documentation. However, if you are writing a virtual comment for an asynchronous function that does not appear in your code, you can use this tag to tell JSDoc that the function is asynchronous.
示例
¥Example
以下示例显示了使用 @async
标签的虚拟注释:
¥The following example shows a virtual comment that uses the @async
tag:
/**
* Download data from the specified URL.
* * @async
* @function downloadData
* @param {string} url - The URL to download from.
* @return {Promise<string>} The data from the URL.
*/