before(asyncId)


当启动异步操作(例如 TCP 服务器接收新连接)或异步操作完成(例如将数据写入磁盘)时,会调用回调函数来通知用户。before 回调会在该回调执行之前调用。asyncId 是分配给即将执行回调的资源的唯一标识符。

【When an asynchronous operation is initiated (such as a TCP server receiving a new connection) or completes (such as writing data to disk) a callback is called to notify the user. The before callback is called just before said callback is executed. asyncId is the unique identifier assigned to the resource about to execute the callback.】

before 回调会被调用 0 到 N 次。如果异步操作被取消,或者例如 TCP 服务器没有收到任何连接,before 回调通常会被调用 0 次。持久的异步资源(如 TCP 服务器)通常会多次调用 before 回调,而其他操作(如 fs.open())只会调用一次。

【The before callback will be called 0 to N times. The before callback will typically be called 0 times if the asynchronous operation was cancelled or, for example, if no connections are received by a TCP server. Persistent asynchronous resources like a TCP server will typically call the before callback multiple times, while other operations like fs.open() will call it only once.】