DEP0157:流中的可线程支持


¥DEP0157: Thenable support in streams

类型:生命结束

¥Type: End-of-Life

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

¥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.

此功能导致用户遇到意想不到的问题,即用户以回调方式实现功能但使用例如 一个会导致错误的异步方法,因为混合 promise 和回调语义是无效的。

¥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();
  },
});