FIND YOUR NEXT FEW LINES

The snippet library.

Small, practical examples. Search by task or narrow things down below.

10 snippets foundClear filters
TypeScriptPromises & iteration protocols

Clean up a generator after an early break

TypeScript: Breaking a for-of loop closes a generator and runs its finally block.

TypeScript✓ Tested
TypeScriptPromises & iteration protocols

Consume an asynchronous sequence

TypeScript: for await waits for each value of an async iterator in sequence.

TypeScript✓ Tested
TypeScriptPromises & iteration protocols

Delegate iteration to another iterable

TypeScript: yield-star forwards items from another iterable while retaining generator composition.

TypeScript✓ Tested
TypeScriptPromises & iteration protocols

Inspect both successful and failed promise results

TypeScript: allSettled preserves input order and reports failures without rejecting the combined promise.

TypeScript✓ Tested
TypeScriptPromises & iteration protocols

Produce a lazy sequence with a generator

TypeScript: A generator yields one value per iteration without building an intermediate array.

TypeScript✓ Tested
TypeScriptPromises & iteration protocols

Recover from an expected promise rejection

TypeScript: Return a fallback from catch so later handlers receive an ordinary resolved value.

TypeScript✓ Tested
TypeScriptPromises & iteration protocols

Run cleanup after a promise settles

TypeScript: finally runs after success or failure and normally preserves the original outcome.

TypeScript✓ Tested
TypeScriptPromises & iteration protocols

Run dependent async steps in order

TypeScript: Await one result before using it as the input of the next calculation.

TypeScript✓ Tested
TypeScriptPromises & iteration protocols

Transform a resolved promise result

TypeScript: A then handler returns the value passed to the next promise in the chain.

TypeScript✓ Tested
TypeScriptPromises & iteration protocols

Use the first fulfilled promise result

TypeScript: Promise.any ignores individual rejections until one input fulfills.

TypeScript✓ Tested