Skip to content
PromptLab by FEHMER TECH
ENDE
Coding

Async/Await Patterns

Implement asynchronous programming correctly with parallelization and error handling.

Prompt template

Refactor and optimize the asynchronous programming in the following [PROGRAMMING LANGUAGE] code:

**Current Code:**
```[PROGRAMMING LANGUAGE]
[INSERT CODE HERE]
```

**Please analyze and improve:**
1. **Parallelization:** Identify independent async operations and run them in parallel (Promise.all, asyncio.gather, etc.)
2. **Error Handling:** Implement correct error handling for all async paths
3. **Race Conditions:** Identify and fix potential race conditions
4. **Cancellation:** Implement cancellation capabilities (AbortController, CancellationToken)
5. **Throttling/Debouncing:** Limit parallel requests where needed
6. **Memory Leaks:** Check for unhandled promises and missing cleanup logic
7. **Timeout Handling:** Add timeouts for external calls

**Patterns to check:**
- Sequential vs. parallel execution
- Promise.allSettled for fault-tolerant parallelism
- Async iterators for streaming
- Semaphore pattern for limited concurrency

Show the optimized code with explanations.

Replace placeholders in [square brackets]: [PROGRAMMING LANGUAGE][INSERT CODE HERE]

How to use this template

Copy the prompt, replace the placeholders in square brackets with your details and paste it into the AI assistant of your choice. The more precise your details, the better the result.

Tips for better results

  • Mark which operations depend on each other
  • Specify whether external APIs are called
  • Ask about concurrency limits for API calls
  • Request sequence diagrams for the async flow

Suitable open models

The selection names current open models as a starting point for your own tests. It is not a measurement for this template.

Keywords: #async #concurrency #promises #parallelism

Last updated: