@helia/verified-fetch
Version:
A fetch-like API for obtaining verified & trustless IPFS content on the web
19 lines • 852 B
JavaScript
export async function serverTiming(name, description, fn) {
const startTime = performance.now();
try {
const result = await fn(); // Execute the function
const endTime = performance.now();
const duration = (endTime - startTime).toFixed(1); // Duration in milliseconds
// Create the Server-Timing header string
const header = `${name};dur=${duration};desc="${description}"`;
return { result, header, error: null };
}
catch (error) {
const endTime = performance.now();
const duration = (endTime - startTime).toFixed(1);
// Still return a timing header even on error
const header = `${name};dur=${duration};desc="${description}"`;
return { result: null, error, header }; // Pass error with timing info
}
}
//# sourceMappingURL=server-timing.js.map