DEP0157:流中的可 then 对象支持
【DEP0157: Thenable support in streams】
类型:寿命终止
【Type: End-of-Life】
Node.js 流的一个未记录功能是支持在实现方法中使用 thenable。这现已被弃用,请改用回调,并避免在流的实现方法中使用异步函数。
【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();
},
});