JSDoc 中文网

语法

🌐 Syntax

@async

概述

🌐 Overview

@async 标签表示一个函数是 异步,这意味着它使用语法 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:

带有 @async 标签的虚拟注释
/**
 * 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.
 */