Promise.then Job execution order

前端 未结 3 1221
灰色年华
灰色年华 2020-12-02 02:52

The spec says (para 5):

The PendingJob records from a single Job Queue are always initiated in FIFO order. This specification does not define th

3条回答
  •  忘掉有多难
    2020-12-02 03:27

    setTimeout does not mean that the supplied function will be executed after the provided time. It adds the function to the end of the queue once the delay has elapsed.

    It really depends on when your promise resolves, as to the execution of the two statements. In your example, setTimeout will add it's callback to the queue ahead of the resolved promise, so you can expect one two.

提交回复
热议问题