Home Polymers this.async vs Promise.then vs setTimeout
Reply: 1

Polymers this.async vs Promise.then vs setTimeout

simplesystems Published in 2017-12-07 12:12:57Z

Whats the difference between Polymers this.async, Promise.then and setTimeout function?

My understanding:

this.async and Promise.then moves a Task to the end of the current Stack and setTimeout is handled as new Task and executed in the next loop when the eventloop takes a new task from the queue?

Please correct me if I am wrong.

tony19 Reply to 2017-12-11 16:36:42Z

TLDR: Yes, but note this.async uses setTimeout if a timeout is specified.

  • Polymer.Async.run (this.async) without timeout - queues a microtask (via a MutationObserver callback)
  • Polymer.Async.run (this.async) with timeout - queues a macrotask
  • Promise.then - queues a microtask
  • setTimeout - queues a macrotask

Difference between microtask and macrotask within an event loop context

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.30279 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO