销毁


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

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

Http2Stream 实例被销毁时,则将尝试向连接的对等方发送 RST_STREAM 帧。

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

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

All Http2Stream instances are destroyed either when:

  • An RST_STREAM frame for the stream is received by the connected peer, and (for client streams only) pending data has been read.
  • The http2stream.close() method is called, and (for client streams only) pending data has been read.
  • The http2stream.destroy() or http2session.destroy() methods are called.

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

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.

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.