queueMicrotask(callback)
添加於:v11.0.0
參數
callback
<Function> 要排隊的函數。
queueMicrotask()
方法將要調用的微任務排隊callback
.如果callback
拋出異常,process
對象 'uncaughtException'
將發出事件。
微任務隊列由 V8 管理,使用方式與
隊列類似,後者由 Node.js 管理。 process.nextTick()
process.nextTick()
隊列總是在 Node.js 事件循環的每一輪中的微任務隊列之前處理。
// Here, `queueMicrotask()` is used to ensure the 'load' event is always
// emitted asynchronously, and therefore consistently. Using
// `process.nextTick()` here would result in the 'load' event always emitting
// before any other promise jobs.
DataHandler.prototype.load = async function load(key) {
const hit = this._cache.get(key);
if (hit !== undefined) {
queueMicrotask(() => {
this.emit('load', hit);
});
return;
}
const data = await fetchData(key);
this._cache.set(key, data);
this.emit('load', data);
};
相關用法
- Node.js querystring.unescape()用法及代碼示例
- Node.js querystring.parse()用法及代碼示例
- Node.js querystring.decode()用法及代碼示例
- Node.js querystring.stringify(obj[, sep[, eq[, options]]])用法及代碼示例
- Node.js querystring.encode()用法及代碼示例
- Node.js querystring.escape()用法及代碼示例
- Node.js querystring.parse(str[, sep[, eq[, options]]])用法及代碼示例
- Node.js querystring.stringify()用法及代碼示例
- Node.js ServerHttp2Stream http2stream.pushStream(headers[, options], callback)用法及代碼示例
- Node.js http2.Http2ServerRequest request.url用法及代碼示例
- Node.js request.socket用法及代碼示例
- Node.js assert.notEqual(actual, expected[, message])用法及代碼示例
- Node.js tlsSocket.authorized用法及代碼示例
- Node.js zlib.deflateRaw()用法及代碼示例
- Node.js http.IncomingMessage message.rawHeaders用法及代碼示例
- Node.js Console用法及代碼示例
- Node.js GM transparent()用法及代碼示例
- Node.js URL.protocol用法及代碼示例
- Node.js http.Agent.reuseSocket(socket, request)用法及代碼示例
- Node.js fs.filehandle.datasync()用法及代碼示例
- Node.js socket.bind()用法及代碼示例
- Node.js v8.getHeapSpaceStatistics()用法及代碼示例
- Node.js http2session.destroyed用法及代碼示例
- Node.js http.ServerResponse response.statusCode用法及代碼示例
- Node.js Buffer buf.writeBigUInt64BE(value[, offset])用法及代碼示例
注:本文由純淨天空篩選整理自nodejs.org大神的英文原創作品 queueMicrotask(callback)。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。