我正在编写一个 Cloudflare Worker,它需要在我的原始请求完成后 ping 分析服务。我不希望它阻止原始请求,因为我不希望延迟或分析系统故障减慢或中断请求。如何创建在原始请求完成后开始和结束的请求?
addEventListener('fetch', event => {
event.respondWith(handle(event))
})
async function handle(event) {
const response = await fetch(event.request)
// Send async analytics request.
let promise = fetch("https://example.com")
.then(response => {
console.log("analytics sent!")
})
// If I uncomment this, only then do I see the
// "analytics sent!" log message. But I don't
// want to wait for it!
// await promise;
return response
}