Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
Rampaging

Azriel Axighi

💭
Rampaging
View GitHub Profile
View cachedFetch.js
const cachedFetch = (url, options) => {
let expiry = 5 * 60 // 5 min default
if (typeof options === 'number') {
expiry = options
options = undefined
} else if (typeof options === 'object') {
// I hope you didn't set it to 0 seconds
expiry = options.seconds || expiry
}
// Use the URL as the cache key to sessionStorage
View async_runner.js
let fs = require("fs");
function run(taskDef) {
// create the iterator
let task = taskDef();
// start the task
let result = task.next();