Is setTimeout not the same as this.async?

Sometimes I am mistaken in coding my web application and material for your polymer 1.0, which stops working correctly. It’s like setting data on some user element and then immediately trying to read some data from it (it depends on the data just installed) (because I don’t know better). Sometimes it doesn’t work. Most of the time this.asyncwill help me, but sometimes it will not. However, he setTimeoutnever brought me to me in such situations. In most cases, a call setTimeoutwithout waiting time will work just as well.

For a long time I thought that this.async(function(){...})coincides with setTimeout(function(){...}). Because sometimes the code inside this.asyncwill not be able to see changes in the data of user elements, but the code setTimeoutwill not be inside .

Are these two methods implemented differently?

+4
source share
1 answer

this.asyncAdds your function to the beginning of the event queue, and setTimeoutadds it to the end. If you use setTimeoutother functions can be executed before calling your function, which will lead to changes that you can see in your data.

From the documentation this.async :

, ( , , )

setTimeout, , , " " .

setTimeout , . , ; , , setTimeout .

+6

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


All Articles