Skip to Content
0 likes
Running Many Requests at Once With asyncio.gather Level: Advanced

asyncio.gather runs many waiting tasks at once in one thread and returns results in order. Avoid await in a loop and blocking calls, keep failures with return_exceptions=True, and limit concurrency with a Semaphore.

0 likes
Speeding Up Many Downloads in Python With ThreadPoolExecutor Level: Advanced

Downloads spend most of their time waiting. ThreadPoolExecutor lets many waits overlap: 20 half-second downloads in 2 seconds instead of 10. Handle failures with as_completed, pick a sensible worker count and respect the server.

0 likes
fetch With Proper Error Handling (It Doesn't Throw on 404) Level: Intermediate

fetch only rejects when there's no response. A 404 or 500 resolves normally, so check response.ok, add a timeout, and keep the status on the error so the caller can decide what to tell the user.

0 likes
Fix "Unexpected token in JSON" Errors Level: Intermediate

"Unexpected token in JSON" means JSON.parse got text that isn't JSON. Read the exact message, log the raw text, and match it to one of five causes. Most of the time it's an HTML error or login page.

0 likes
Batch API Calls With Promise.allSettled Level: Advanced

Send many requests, keep the successes, and report the failures instead of losing everything to one rejected promise. Plus limiting how many run at once.

0 likes
Add a Timeout to fetch With AbortController Level: Advanced

fetch has no timeout option and can wait a very long time. AbortSignal.timeout(ms) fixes that in one line, and AbortSignal.any combines it with a cancel button.

0 likes
Paginate an API With an Async Generator Level: Advanced

Hide page numbers and "next" links inside an async generator, then loop over every record with for await. Stop early and the remaining pages are never fetched.

0 likes
Discriminated Unions for success and error Responses Level: Intermediate

Replace a data-or-error object with a union tagged by success, then add a generic Outcome and an unwrap helper. After this, the compiler knows which property exists in each case.

0 likes
Type JSON from fetch Without as MyType Everywhere Level: Intermediate

Replace scattered casts with one assertion function and one typed fetch helper. After this, a 404 or a changed payload fails with a clear message instead of carrying a wrong type.

0 likes
unknown First, Then Narrow: Parse an API Payload Level: Intermediate

Receive a nested payload as unknown and narrow it with two small helpers until every property is checked. After this, you can write a parser that rejects wrong data and returns a real type.

0 likes
Augment Express Request Without Fighting the Compiler Level: Advanced

Add a user property to the Express request type with a module augmentation in one declaration file. After this, middleware and handlers agree on the type and you avoid the mistake that floods node_modules with errors.

0 likes
Template Literal Types for /users/:id Routes Level: Advanced

Turn a route pattern into a type that finds the parameter names and checks the paths you pass. After this, a typo in a route or a missing parameter is a compile error.