-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
38 lines (32 loc) · 976 Bytes
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const URL_BASE = 'https://dev.anthum.com/sleep.php'
const RESPONSE_DELAY = 2 // seconds
const NUM_REQUESTS = 1
let loads = 0
navigator.serviceWorker.register('/sw.js')
document.addEventListener('DOMContentLoaded', e => {
document.querySelector('#reload').onclick = load
})
function load() {
// loadSingle()
loadMany()
}
load()
// HTTP is used to specifically create brower
async function loadMany() {
const groupId = performance.now()
const url = `${URL_BASE}?s=${RESPONSE_DELAY}&group=${++loads}#groupId=${groupId}`
const promises = []
for (let i=0; i < NUM_REQUESTS; i++) {
promises.push(
fetch(url)
.catch(e => console.error('❌', e))
)
}
const responses = await Promise.allSettled(promises).catch(e => {})
console.log('✅ all settled', responses)
}
function loadSingle() {
fetch(`${URL_BASE}?s=2#groupId=${performance.now()}`)
.then(resp => console.log('✅', resp))
.catch(e => console.error('❌', e.name))
}