0% found this document useful (0 votes)
8 views10 pages

Master Async Programming: 20 JavaScript Tasks

The document outlines 20 tasks designed to enhance JavaScript skills in asynchronous programming and promises, ranging from beginner to complex levels. Each task simulates real-world scenarios, such as API calls, error handling, and performance optimization techniques. The tasks aim to provide practical experience with concepts like Promise.race, caching, and rate limiting, essential for mastering async operations in production-like environments.

Uploaded by

prajot
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views10 pages

Master Async Programming: 20 JavaScript Tasks

The document outlines 20 tasks designed to enhance JavaScript skills in asynchronous programming and promises, ranging from beginner to complex levels. Each task simulates real-world scenarios, such as API calls, error handling, and performance optimization techniques. The tasks aim to provide practical experience with concepts like Promise.race, caching, and rate limiting, essential for mastering async operations in production-like environments.

Uploaded by

prajot
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

10/3/25, 11:11 AM 20 Async/Promises Tasks - JavaScript

20 Async/Promises Tasks in JavaScript


Production-like Practice for Mastering Async Programming

Practicing async programming and promises in production-like environments will level


up your JavaScript skills. These tasks range from simple to complex and mimic real-
world problems you'd encounter in backend/frontend projects.

Beginner / Foundations

Task 1
Simulate API Calls with setTimeout

Write a function that fetches "user data" after a random delay.


Use Promise and async/await to return the result.
Add error handling for "failed requests."

BEGINNER

What you'll learn:


Understanding the basics of Promise construction, resolve/reject patterns,
and how async/await simplifies promise-based code. This is fundamental to
all asynchronous JavaScript operations.

Task 2
Sequential vs Parallel Requests

Make 3 fake API calls:

Run them sequentially (one after another).


Run them in parallel with [Link] .
[Link] 1/10
10/3/25, 11:11 AM 20 Async/Promises Tasks - JavaScript

Compare execution times.

BEGINNER

What you'll learn:


Understanding the performance difference between sequential (await in
loop) vs parallel execution ([Link]). In production, parallel requests can
dramatically reduce load times when operations don't depend on each other.

Task 3
Retry Mechanism

Create a function that retries a failed API call up to 3 times before throwing an
error.

BEGINNER

What you'll learn:


Implementing retry logic is crucial for handling transient network failures.
This pattern is used extensively in production systems to improve reliability.
You'll learn about recursive async functions and error propagation.

Task 4
[Link]() Loader

Simulate a loader that shows whichever API responds first (weather API vs news
API).

BEGINNER

What you'll learn:


[Link]() resolves with the first settled promise. This is useful for
implementing fallback systems, timeout mechanisms, or showing the fastest

[Link] 2/10
10/3/25, 11:11 AM 20 Async/Promises Tasks - JavaScript

response in competitive scenarios.

Task 5
Timeout Wrapper

Write a function fetchWithTimeout(api, ms) that rejects if API doesn't


respond in ms milliseconds.

BEGINNER

What you'll learn:


Combining [Link]() with a timeout promise to prevent hanging
requests. Essential for production systems where you need to guarantee
response times and fail fast when services are slow.

Intermediate / Applied

Task 6
Paginated Data Fetch

Simulate fetching paginated results from an API ( page=1,2,3… ).


Use async iteration ( for await…of ) to fetch until all pages are received.

INTERMEDIATE

What you'll learn:


Working with paginated APIs is extremely common in production. You'll learn
async iterators, handling dynamic loops with async operations, and
accumulating results across multiple requests. Many APIs (GitHub, Twitter,
etc.) use pagination.

[Link] 3/10
10/3/25, 11:11 AM 20 Async/Promises Tasks - JavaScript

Task 7
Queueing API Requests

Write a queue system that processes max 2 requests at a time.


New requests must wait until one finishes.

INTERMEDIATE

What you'll learn:


Implementing concurrency control is critical to prevent overwhelming servers
or hitting rate limits. This teaches you about job queues, managing async
pools, and controlling parallel execution - patterns used in worker queues
like Bull or BeeQueue.

Task 8
Chained API Calls

Example:

Fetch user → user's posts → post comments .


Each depends on the previous result.

INTERMEDIATE

What you'll learn:


Understanding dependent async operations and data flow. This is common
in REST APIs where you need to fetch related resources. You'll practice
passing data between async calls and handling errors in chains.

Task 9
Batch Requests with Delay

Accept 100 fake requests but process them in batches of 10 every 2 seconds.
[Link] 4/10
10/3/25, 11:11 AM 20 Async/Promises Tasks - JavaScript

INTERMEDIATE

What you'll learn:


Batch processing is essential for handling large datasets or respecting API
rate limits. You'll learn to chunk arrays, use delays between batches, and
aggregate results - techniques used in ETL pipelines and data migration
scripts.

Task 10
Web Scraper Simulation

Use [Link] to fetch multiple URLs.


Store successful results, log failures.

INTERMEDIATE

What you'll learn:


[Link] waits for all promises to complete regardless of
success/failure, unlike [Link] which fails fast. Critical for batch
operations where you want to process partial results even if some operations
fail.

Advanced / Production-like

Task 11
Cache Layer for API Calls

Implement caching:

If data exists in cache, return it.


Else fetch and store.
Add an expiry time (TTL - Time To Live).

[Link] 5/10
10/3/25, 11:11 AM 20 Async/Promises Tasks - JavaScript

ADVANCED

What you'll learn:


Caching reduces API calls and improves performance. You'll implement TTL
logic, cache invalidation, and learn about the cache-aside pattern used in
Redis, Memcached, and other caching systems. Essential for scalable
applications.

Task 12
Debounced API Search

Simulate a search input where typing triggers API calls.


Use debounce + promises so only the last keystroke makes the call.

ADVANCED

What you'll learn:


Debouncing prevents excessive API calls during rapid user input. You'll learn
to cancel pending requests and only execute the most recent one - critical
for search autocomplete, form validation, and any user-input-driven API
calls.

Task 13
File Upload with Progress Bar

Simulate breaking a large file into chunks.


Upload chunks sequentially or in parallel.
Show progress updates.

ADVANCED

What you'll learn:

[Link] 6/10
10/3/25, 11:11 AM 20 Async/Promises Tasks - JavaScript

Chunked uploads are used for large files to handle network interruptions and
provide progress feedback. You'll learn about tracking async operation
progress, resumable uploads, and handling partial failures - techniques used
by services like Google Drive and Dropbox.

Task 14
Circuit Breaker Pattern

If an API fails 5 times in a row, stop calling it for 10 seconds.


Then retry.

ADVANCED

What you'll learn:


Circuit breakers prevent cascading failures in distributed systems. When a
service is down, you stop calling it to allow recovery time. This pattern is
fundamental in microservices architecture and used by libraries like Hystrix
and Resilience4j.

Task 15
Polling System

Build a function that polls an API every 3 seconds until a condition


( status=done ) is met.

ADVANCED

What you'll learn:


Polling is used for long-running operations like file processing, payment
verification, or job status checks. You'll learn recursive async patterns,
conditional termination, and backoff strategies. Alternative to WebSockets for
simpler use cases.

[Link] 7/10
10/3/25, 11:11 AM 20 Async/Promises Tasks - JavaScript

Complex / System-like

Task 16
Worker Pool for CPU Tasks

Use Promise + async queue to process tasks in worker-like manner.


Example: Image resize jobs, max 4 at a time.

COMPLEX

What you'll learn:


Worker pools manage resource-intensive tasks by limiting concurrent
execution. You'll implement a job scheduler similar to what's used in
background job processors. Understanding this helps with scaling CPU-
bound operations and preventing server overload.

Task 17
Streaming Data Simulation

Use async generators ( async function* ) to yield chunks of data from an


API.
Consume them with for await…of .

COMPLEX

What you'll learn:


Async generators enable processing large datasets without loading
everything into memory. Used for streaming responses, reading large files,
or processing real-time data feeds. This pattern is fundamental for building
efficient data pipelines.

[Link] 8/10
10/3/25, 11:11 AM 20 Async/Promises Tasks - JavaScript

Task 18
Cancel an Ongoing Request

Implement with AbortController .


Example: User navigates away before fetch completes.

COMPLEX

What you'll learn:


AbortController allows cancelling fetch requests to prevent memory leaks
and unnecessary processing. Critical in SPAs where users navigate between
pages quickly. Also used for implementing request timeouts and cleaning up
resources.

Task 19
Rate Limiter (Token Bucket)

Implement an API rate limiter: max 5 requests per second.


Queue excess requests.

COMPLEX

What you'll learn:


Rate limiting prevents API abuse and ensures fair resource usage. The
token bucket algorithm is used by major APIs (Twitter, GitHub, Stripe). You'll
learn about sliding windows, token replenishment, and request queueing
strategies.

Task 20
Distributed Promise Handling

Simulate microservices:

[Link] 9/10
10/3/25, 11:11 AM 20 Async/Promises Tasks - JavaScript

Service A calls Service B & C.


B depends on A, C runs in parallel.
Aggregate results at the end with error handling.

COMPLEX

What you'll learn:


Orchestrating multiple dependent and independent services is the
foundation of microservices architecture. You'll handle complex async flows,
partial failures, and result aggregation - skills essential for building
distributed systems.

How to Practice Like Production

Use [Link] with fetch/axios for making HTTP requests.

Add real APIs (like GitHub API, OpenWeatherMap, JSONPlaceholder).

Add error handling, logging, retries, and timeouts to every function.

Wrap everything in reusable utility functions (like you'd do in production).

Use [Link]/timeEnd to measure performance.

Implement proper TypeScript types if using TypeScript.

Write unit tests for your async utilities.

[Link] 10/10

You might also like