DEP0157: 流中的 Thenable 支持


类型: 生命结束

Node.js 流的一个未记录的特性是在实现方法中支持 thenables。 现在已弃用,请改用回调并避免将异步函数用于流的实现方法。

此特性导致用户遇到意外问题,用户以回调风格实现函数但使用例如异步方法,由于混合 promise 和回调语义无效,因此会导致错误。

const w = new Writable({
  async final(callback) {
    await someOp();
    callback();
  },
});

Type: End-of-Life

An undocumented feature of Node.js streams was to support thenables in implementation methods. This is now deprecated, use callbacks instead and avoid use of async function for streams implementation methods.

This feature caused users to encounter unexpected problems where the user implements the function in callback style but uses e.g. an async method which would cause an error since mixing promise and callback semantics is not valid.

const w = new Writable({
  async final(callback) {
    await someOp();
    callback();
  },
});