[ Web Proxy ]
URL:
Viewing: https://uk.javascript.info/microtask-queue [Back]  [Original]

:
DanskEnglishEspaolFranaisIndonesiaItalianoTrkeOzbek

.then/.catch/.finally .

, , .then/.catch/.finally .

:

let promise = Promise.resolve();

promise.then(() => alert(" !"));

alert(" "); //  alert  

, , !.

, , , .

.then ? ?

. ECMA PromiseJobs, ( v8).

:

  • ---: , .
  • , .

, , , .then/catch/finally ; . JavaScript , .

.

[]

.

.then/catch/finally, . , , .

, ? , ?

, .then:

Promise.resolve()
  .then(() => alert(" !"))
  .then(() => alert(" "));

.

unhandledrejection : ?

, JavaScript .

, .

, , .catch :

let promise = Promise.reject(new Error("  !"));
promise.catch(err => alert(''));

//  :  
window.addEventListener('unhandledrejection', event => alert(event.reason));

.catch, , , :

let promise = Promise.reject(new Error("  !"));

//   !
window.addEventListener('unhandledrejection', event => alert(event.reason));

, ? :

let promise = Promise.reject(new Error("  !"));
setTimeout(() => promise.catch(err => alert('')), 1000);

// Error:   !
window.addEventListener('unhandledrejection', event => alert(event.reason));

, , !, .

, : unhandledrejection? !

, unhandledrejection , : , , - rejected, .

.catch, setTimeout, . , , unhandledrejection , .

, promise jobs, ( v8).

.then/catch/finally .

, .then/catch/finally, .then.

Javascript, Node.js, (event loop) . , , (event loop): (microtasks) (macrotasks).

,

Web Proxy Viewer  |  New URL  |  Original Page