


Will await wait when Promise is not resolved or rejected in JavaScript?
JavaScript asynchronous programming: pending states of async/await
and promises
async/await
is an elegant way to handle asynchronous operations in JavaScript, but its behavior is worth exploring in depth when the Promise is in a long-term pending state. This article will analyze the performance of await
when the Promise is not resolve
or reject
.
Scenario Analysis
Consider the following code:
async function yyy() { console.log('yyy calls xxx to start'); let res = await xxx(); console.log('yyy call xxx ends', res); } async function xxx() { return new Promise(function(resolve, reject) { // No resolve or reject call}); } yyy();
The xxx
function returns a promise that is always in the pending state. What happens with await xxx()
in the yyy
function?
Environment Differences: Node.js vs. Browser
The behavior of await
is affected by the operating environment:
Node.js: If Promise remains pending and there are no other active asynchronous operations (such as timers, network requests), the Node.js event loop will consider the program to be completed and exited. It won't wait for the pending Promise indefinitely.
Browser: In a browser environment, await
will usually wait for the Promise to complete. However, if other asynchronous tasks are lacking to drive the event loop, the browser engine may think that the script has been executed and will not block page rendering or interaction. But if the script is executed synchronously (for example, directly

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



The main sources of H5 page materials are: 1. Professional material website (paid, high quality, clear copyright); 2. Homemade material (high uniqueness, but time-consuming); 3. Open source material library (free, need to be carefully screened); 4. Picture/video website (copyright verified is required). In addition, unified material style, size adaptation, compression processing, and copyright protection are key points that need to be paid attention to.

The H5 page needs to be maintained continuously, because of factors such as code vulnerabilities, browser compatibility, performance optimization, security updates and user experience improvements. Effective maintenance methods include establishing a complete testing system, using version control tools, regularly monitoring page performance, collecting user feedback and formulating maintenance plans.

When the number of elements is not fixed, how to select the first child element of the specified class name through CSS. When processing HTML structure, you often encounter different elements...

H5 (HTML5) is suitable for lightweight applications, such as marketing campaign pages, product display pages and corporate promotion micro-websites. Its advantages lie in cross-platformity and rich interactivity, but its limitations lie in complex interactions and animations, local resource access and offline capabilities.

The problem of container opening due to excessive omission of text under Flex layout and solutions are used...

PS "Loading" problems are caused by resource access or processing problems: hard disk reading speed is slow or bad: Use CrystalDiskInfo to check the hard disk health and replace the problematic hard disk. Insufficient memory: Upgrade memory to meet PS's needs for high-resolution images and complex layer processing. Graphics card drivers are outdated or corrupted: Update the drivers to optimize communication between the PS and the graphics card. File paths are too long or file names have special characters: use short paths and avoid special characters. PS's own problem: Reinstall or repair the PS installer.

A PS stuck on "Loading" when booting can be caused by various reasons: Disable corrupt or conflicting plugins. Delete or rename a corrupted configuration file. Close unnecessary programs or upgrade memory to avoid insufficient memory. Upgrade to a solid-state drive to speed up hard drive reading. Reinstalling PS to repair corrupt system files or installation package issues. View error information during the startup process of error log analysis.

How to use locally installed font files on web pages Have you encountered this situation in web page development: you have installed a font on your computer...
