Asynchronous functions

When window.alert () is called, the script should not wait for user input (for example, pressing ok), it should continue.

How can I achieve without using the setTimeout () function?

this.alert('Window')
console.log('Continue here, dont wait for user input on the "Window"')
+4
source share
3 answers

No. JavaScript is single threaded. You just can't. If the user input hook is not completed, the thread stops there.

You can just tweak / make the DOM look like a warning with style (weird but ok).

+2
source

The warning function pauses further javascript execution until the user clicks the OK button, because the code runs on a single thread.

, , .

() JavaScript

+1

Since JavaScript runs in a single thread, alert / prompt / confirm pauses execution until a response is received from the user.

But there are ways to prevent this: 1. Use the user interface instead of the browser. 2. Using the WebWorkers API 3. Using setTimeout / setInterval 4. Using the requestNextFrame function

0
source

Source: https://habr.com/ru/post/1676241/


All Articles