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

:
Light themeDark theme
DanskEnglishEspaolFranaisIndonesiaItalianoTrkeOzbek

.then/catch/finally .

.then/catch/finally .

:

let promise = Promise.resolve();

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

alert(" "); //     .

' , ' !' .

. .

.then ? .

. ECMA PromiseJobs (internal queue) . V8 ' (microtask queue)' .

.

  • (FIFO, first-in-first-out).
  • .

, .then/catch/finally . . .

' .

[]

.

.then/catch/finally , . , .

' !' , ' ? .

. .then .

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

.

unhandledrejection ?

(unhandled rejection) .

' .

.catch .

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

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

.catch , unhandledrejection .

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

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

setTimeout ?

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

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

! , ! .

" unhandledrejection ?" .

unhandledrejection . (rejected) unhandledrejection . .

setTimeout .catch . .catch unhandledrejection ! .

(ES8 ) (promise job) .

.then/catch/finally .

.then/catch/finally .then .

Node.js ' (event loop)' '(macrotask)' . , , .

.

Web Proxy Viewer  |  New URL  |  Original Page