I would like to calcul and display in a file the elapsed time for each call response.
Promise function
function callPromise(ms, promise) {
return new Promise((resolve, reject) => {
const timeoutId = setTimeout(() => {
reject(new Error(`Timeout after ${ms} ms`))
}, ms);
promise.then(
(res) => {
clearTimeout(timeoutId);
resolve(res);
},
(err) => {
clearTimeout(timeoutId);
reject(err);
}
);
})
}
Response call
const response = await callPromise(10, fetch(url, {
method: request.method,
headers: header,
body: body
}))