gpt4 book ai didi

javascript - 锁定 node.js 的 javascript

转载 作者:行者123 更新时间:2023-11-30 18:22:28 25 4
gpt4 key购买 nike

//News object
var newsItem = function(heading, type, time, details, ...)
{
this.heading = heading;
this.type = type;
this.time = time;
this.details = details;
....
};

// array of all newsItem objects
var newsItems = [news1, news2, news....];

我用上面的 node.js 服务器端代码做了两件事:

  1. 我通过从某些新闻站点获取值来更新我的 newsItems 对象。
  2. 我从 newsItems 对象创建 html 以在 UI 上显示它。

问题:

如何确保在更新 newsItems 对象时不使用它来创建 html。

因为这是多线程的,一个线程处理请求,后台线程更新来自新闻站点的对象。我需要在 javascript 中进行某种锁定。我在这里遇到了竞争条件。

非常感谢。

最佳答案

如果您将 Node.js 作为服务器运行,则不需要任何锁定。这是一个单线程环境。

关于javascript - 锁定 node.js 的 javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11734772/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com