Do I need to be concerned with race conditions with asynchronous Javascript?

前端 未结 5 904
悲哀的现实
悲哀的现实 2020-11-29 06:12

Suppose I load some Flash movie that I know at some point in the future will call window.flashReady and will set window.flashReadyTriggered = true.

5条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-29 06:35

    It is important to note that you may still experience race conditions if you eg. use multiple async XMLHttpRequest. Where the order of returned responses is not defined (that is responses may not come back in the same order they were send). Here the output depends on the sequence or timing of other uncontrollable events (server latency etc.). This is a race condition in a nutshell.

    So even using a single event queue (like in JavaScript) does not prevent events coming in uncontrollable order and your code should take care of this.

提交回复
热议问题