“atomic” operation desturbed by asynchronous ajax callbacks

前端 未结 2 1087
独厮守ぢ
独厮守ぢ 2021-01-07 08:17

I know, using the words JavaScript and \'atomic\'-anything in the same sentence is kinda strange, since JavaScript is prised to be asynchronous and therefor not very atomic.

2条回答
  •  醉梦人生
    2021-01-07 08:24

    JavaScript is inherently single-threaded. This means that if AJAX response arrives or timeout/interval should be triggered but other code is running, the response callback/timeout will wait.

    This was one of the primary reasons why JavaScript was chosen for node.js.

    See also:

    • Are there any atomic javascript operations to deal with Ajax's asynchronous nature?

提交回复
热议问题