事件:'abort'
添加於:v15.0.0、v14.17.0
調用 abortController.abort()
方法時會發出 'abort'
事件。使用單個對象參數調用回調,其中單個 type
屬性設置為 'abort'
:
const ac = new AbortController();
// Use either the onabort property...
ac.signal.onabort = () => console.log('aborted!');
// Or the EventTarget API...
ac.signal.addEventListener('abort', (event) => {
console.log(event.type); // Prints 'abort'
}, { once: true });
ac.abort();
與AbortSignal
關聯的AbortController
隻會觸發一次'abort'
事件。我們建議在添加 'abort'
事件偵聽器之前代碼檢查 abortSignal.aborted
屬性是否為 false
。
任何附加到 AbortSignal
的事件偵聽器都應使用 { once: true }
選項(或者,如果使用 EventEmitter
API 附加偵聽器,請使用 once()
方法)以確保事件偵聽器在'abort'
事件已處理。不這樣做可能會導致內存泄漏。
相關用法
- Node.js ClientHttp2Session 'altsvc'事件用法及代碼示例
- Node.js tls.Server 'keylog'事件用法及代碼示例
- Node.js http.Server 'clientError'事件用法及代碼示例
- Node.js cluste 'disconnect'事件用法及代碼示例
- Node.js proces 'exit'事件用法及代碼示例
- Node.js stream.Writable 'pipe'事件用法及代碼示例
- Node.js stream.Readable 'end'事件用法及代碼示例
- Node.js cluste 'fork'事件用法及代碼示例
- Node.js stream.Writable 'unpipe'事件用法及代碼示例
- Node.js Http2Session 'remoteSettings'事件用法及代碼示例
- Node.js Worker 'listening'事件用法及代碼示例
- Node.js tls.Server 'resumeSession'事件用法及代碼示例
- Node.js InterfaceConstructor 'pause'事件用法及代碼示例
- Node.js fs.FSWatcher 'change'事件用法及代碼示例
- Node.js stream.Readable 'data'事件用法及代碼示例
- Node.js http.ClientRequest 'connect'事件用法及代碼示例
- Node.js proces 'uncaughtException'事件用法及代碼示例
- Node.js Http2Session 'localSettings'事件用法及代碼示例
- Node.js REPLServer 'exit'事件用法及代碼示例
- Node.js cluste 'online'事件用法及代碼示例
- Node.js tls.TLSSocket 'session'事件用法及代碼示例
- Node.js Worker 'exit'事件用法及代碼示例
- Node.js cluste 'exit'事件用法及代碼示例
- Node.js Http2Stream 'trailers'事件用法及代碼示例
- Node.js MessagePort 'close'事件用法及代碼示例
注:本文由純淨天空篩選整理自nodejs.org大神的英文原創作品 'abort'事件。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。