當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


Node.js Http2Stream.setTimeout(msecs, callback)用法及代碼示例


http2stream.setTimeout(msecs, callback)

曆史
版本變化
v18.0.0

將無效回調傳遞給 callback 參數現在會拋出 ERR_INVALID_ARG_TYPE 而不是 ERR_INVALID_CALLBACK

v8.4.0

添加於:v8.4.0


參數
const http2 = require('node:http2');
const client = http2.connect('http://example.org:8000');
const { NGHTTP2_CANCEL } = http2.constants;
const req = client.request({ ':path': '/' });

// Cancel the stream if there's no activity after 5 seconds
req.setTimeout(5000, () => req.close(NGHTTP2_CANCEL));

相關用法


注:本文由純淨天空篩選整理自nodejs.org大神的英文原創作品 Http2Stream.setTimeout(msecs, callback)。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。