- JavaScript Async Functions I
- Hello World
- Chained Promises
- Simple Promise
- Promise Rejection
- Promise with Multiple Handlers
- Promise All
- Promise Race
- Async Function with Await
- Async Function with Error Handling
- Chained Promises with Async/Await
- Quiz
- Simple Stopwatch
- Countdown Timer
- Sum Even Numbers in Background
- Simple Text Adventure Game
- JavaScript Async Functions II
This project focuses on mastering asynchronous functions in JavaScript. It includes practical exercises, examples, and small applications focused on work with callbacks, promises, and the async/await
syntax, which are essential for handling tasks like API requests, user interactions, and background operations.
A Simple function wich is using setTimeout
to print a greeting to the console. The first message, "Hello", appears immediately, while the second message, "World", shows up after a 2-second delay. This exercise introduces how JavaScript handles time-based asynchronous functions.
Function chainedPromises()
, using setTimeout
with callbacks, which logs a series of messages to the console in a sequence, with increasing delays, each one is slightly longer from the previous.
Function simplePromise()
which creates a promise that resolves successfully after 2 seconds. You’ll log a success message once the promise completes, demonstrating how promises help manage delayed actions without using nested callbacks.
Function promiseRejection()
which creates a promise that fails after 1 second, logging an error message to the console. This is a common pattern for handling things like failed API requests or unexpected behavior.
Function promiseWithMultipleHandlers()
which chains multiple .then
handlers to the same promise. The promise will be resolved with a message and will log it twice, using two .then()
functions.
Function allPromise()
, that creates three promises each with a different delay, and log the results all at once using Promise.all
, which waits for all promises to complete before proceeding.
Function racePromise()
, helps to handle time-sensitive asynchronous operations by logging the result of whichever promise finishes first. By using Promise.race
which creates three promises that resolve after 1, 2, and 3 seconds respectively and logs the first resolved result.
Async function simplePromiseAsync()
it will await a delayed message and log it to the console. This introduces a cleaner and more readable way to work with asynchronous operations compared to using plain promises.
Async function promiseRejectionAsync()
that throws an error, then catch and log the error by using try/catch
to demonstrate how error management works in asynchronous code
Async function chainedPromisesAsync()
that uses promise chaining, but this time using async/await
. It waits for three promises that resolve after 1, 2, and 3 seconds respectively and logs their results in order.
Simple interactive quiz game that asks questions and uses promises to handle user input and feedback. The game tracks the user’s score and provides final results after all questions are answered.
Creates a basic stopwatch that starts counting in seconds when a button is clicked and stops when the button is clicked again. This introduces the idea of managing real-time updates in asynchronous applications.
Function that creates a countdown timer that counts down from a specified number of seconds. It updates every second and stops when it reaches zero, demonstrating how to use asynchronous functions for time-based tasks.
Function that performs a large calculation in the background, such as summing even numbers, without blocking the main interface. Simulating a long-running task that still allows user interaction, showing how to use async operations to improve user experience.
Function that creates a simple text-based adventure game where the player makes choices and the game responds to those choices. Delays and user input will be handled asynchronously to give a more interactive and dynamic experience.
Function fetchData()
which uses the fetch API to simulate network requests and log the response as JSON. This task introduces real-world asynchronous operations, like fetching data from a server.
Function fetchDataWithErrorHandling()
which expands the fetch function by adding error handling using try/catch
. This is a practical way to manage issues like network failures or server errors when making API requests.
Function fetchParallel()
which handles multiple fetch requests at the same time by making two API calls in parallel and using Promise.all
to wait for both to finish before logging the results.
Function fetchSequential()
Instead of running requests in parallel, it will make two fetch requests in sequence, logging each result as it comes in. This shows how to manage dependent or ordered asynchronous tasks.
Function multiplePromises()
wich uses Promise.allSettled
to handle promises that may either resolve or reject. It will create multiple promises with different outcomes and log whether each one succeeded or failed.
Function startRetry()
that retries a promise if it fails, attempting up to three times before giving up. This is a practical pattern for handling unreliable network requests or other asynchronous tasks.
Function throttlePromises()
which throttles promises by limiting the number of promises that run concurrently. This is useful when working with APIs that have rate limits or when managing heavy resource usage.
Function fetchWithTimeout()
wich implements a fetch request with a timeout, rejecting the promise if the request takes too long. This technique is helpful for ensuring that your application doesn’t wait indefinitely for a response.
Class AsyncQueue()
which creates an asynchronous task queue that processes one task at a time. This is a great way to manage tasks that need to be executed in order but may have varying completion times.
Combine the power of async/await with JavaScript generators to handle complex sequences of asynchronous tasks. This task gives you a deeper understanding of how to manage advanced asynchronous flows.
This project is licensed under the MIT License. See the LICENSE file for details.
For any questions or suggestions, please open an issue in the repository.