cloud_off
You are offline. Reconnect to keep browsing.
data_object
Snippet library
Copy-ready, tested snippets for Python, Flask, JavaScript, SQL, HTML, CSS and Bash. Open any of them in the playground.
Show only snippets saved in this browser
2 snippets
javascript
star
bookmark_border
Abort a fetch that takes too long and handle HTTP errors.
async function getJSON(url, { timeout = 8000, ...options } = {}) {
const controller = new AbortController();
const timer = setTimeout(() => controller.abort(), timeout);
try {
const res = await fetch(url, { ...options, signal: controller.signal });
intermediate
#fetch #network #async
javascript
bookmark_border
Process many async jobs, but only N at a time.
async function mapLimit(items, limit, worker) {
const results = new Array(items.length);
let next = 0;
async function lane() {
while (next < items.length) {
advanced
#async #promises #performance
bookmark_border No saved snippets on this page yet. Use the bookmark button to save one.
groups
Join PandaDev
Learning with us? Developers and designers can apply to work on real client projects with the team.
person_add Apply to join