简体   繁体   English

节点js中的自销毁对象

[英]Self destruct object in node js

For some reasons, I don't want make a loop through a object array to check their expirations and remove them out. 由于某些原因,我不想遍历对象数组以检查其到期并将其删除。 I am looking for a mechanism that automatically set object to kill itself and implement it with 我正在寻找一种机制,该机制可以自动设置对象以杀死自己并使用

function obj = {
    var self = this;
    setTimeout{ function{
        //destroy
        self = undefined;
    }, 14280 }
}
var my_Obj = new obj

Just only one thing I wonder whether this pattern make heavy load for system or not.?. 我只想知道一件事,这种模式是否会使系统负担沉重? I just start investigate in nodeJS so have no idea about timer and it's relation in nodeJS. 我只是开始在nodeJS中进行调查,因此不了解计时器及其在nodeJS中的关系。 As my experiences in C#, if each object handler it own timer may let system becomes heavy and slow 根据我在C#中的经验,如果每个对象处理程序都有自己的计时器,则可能会使系统变得沉重而缓慢

Node.js starts an implicit event loop in a single thread that uses blocking asynchronous callbacks for processing. Node.js在单个线程中启动一个隐式事件循环,该线程使用阻塞的异步回调进行处理。 Since this is a dominant runtime feature, the event loop will happily handle as many callbacks as you can register. 由于这是主要的运行时功能,因此事件循环将愉快地处理您可以注册的尽可能多的回调。

You usually shouldn't have to worry about the event loop starving your process and if you feel your handling too many things at any given point in time, you can always spread out across multiple processes in a cluster. 通常,您不必担心事件循环会使您的进程感到饥饿,并且如果您觉得在任何给定的时间点都处理太多的事情,那么您始终可以分散在集群中的多个进程中。

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

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