setImmediate vs. nextTick

后端 未结 7 664
野的像风
野的像风 2020-11-22 12:26

Node.js version 0.10 was released today and introduced setImmediate. The API changes documentation suggests using it when doing recursive nextTick

7条回答
  •  长发绾君心
    2020-11-22 13:12

    I recommend you to check docs section dedicated for Loop to get better understanding. Some snippet taken from there:

    We have two calls that are similar as far as users are concerned, but their names are confusing.

    • process.nextTick() fires immediately on the same phase

    • setImmediate() fires on the following iteration or 'tick' of the
      event loop

    In essence, the names should be swapped. process.nextTick() fires more immediately than setImmediate(), but this is an artifact of the past which is unlikely to change.

提交回复
热议问题