解构


【Destruction】

所有 Http2Stream 实例都会在以下情况被销毁:

【All Http2Stream instances are destroyed either when:】

  • 已由连接的对等方接收到该流的 RST_STREAM 帧,并且(仅对于客户端流)已读取了挂起的数据。
  • http2stream.close() 方法被调用,并且(仅对于客户端流)挂起的数据已被读取。
  • http2stream.destroy()http2session.destroy() 方法被调用。

当一个 Http2Stream 实例被销毁时,将尝试向已连接的对等端发送一个 RST_STREAM 帧。

【When an Http2Stream instance is destroyed, an attempt will be made to send an RST_STREAM frame to the connected peer.】

Http2Stream 实例被销毁时,将会触发 'close' 事件。由于 Http2Streamstream.Duplex 的一个实例,如果流数据当前正在流动,还会触发 'end' 事件。如果 http2stream.destroy() 被调用时传入了一个 Error 作为第一个参数,也可能会触发 'error' 事件。

【When the Http2Stream instance is destroyed, the 'close' event will be emitted. Because Http2Stream is an instance of stream.Duplex, the 'end' event will also be emitted if the stream data is currently flowing. The 'error' event may also be emitted if http2stream.destroy() was called with an Error passed as the first argument.】

Http2Stream 被销毁后,http2stream.destroyed 属性将为 truehttp2stream.rstCode 属性将指定 RST_STREAM 错误代码。一旦 Http2Stream 实例被销毁,就无法再使用。

【After the Http2Stream has been destroyed, the http2stream.destroyed property will be true and the http2stream.rstCode property will specify the RST_STREAM error code. The Http2Stream instance is no longer usable once destroyed.】