简体   繁体   English

安全推送阵列,如何? 担心与否?

[英]push to array safely, how to? worry or not?

I think this may be a naive question. 我认为这可能是一个天真的问题。 I often find that I've got multiple xhr requests waiting on returns. 我经常发现我有多个等待返回的xhr请求。 I keep track of the requests I've issued in a javascript array. 我跟踪我在javascript数组中发出的请求。 that is, when a new request is made, I add it to the array, then when the thread completes I remove it from the array. 也就是说,当一个新请求发出时,我将它添加到数组中,然后当线程完成时我将它从数组中删除。

In a multi-threaded OS, I'd be worried about threads crossing but I know javascript is single threaded. 在多线程操作系统中,我会担心线程交叉,但我知道javascript是单线程的。 Should I worry about the array being consistent? 我应该担心阵列是否一致?

Sorry if this has been asked and and answered. 对不起,如果已经询问并回答了这个问题。 I looked and did not find a link around array safe push. 我看了,没有找到阵列安全推送的链接。

No, you should not worry about it. 不,你不应该担心。 JavaScript is single-threaded, like you said. JavaScript是单线程的,就像你说的那样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM