简体   繁体   中英

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. As my experiences in C#, if each object handler it own timer may let system becomes heavy and slow

Node.js starts an implicit event loop in a single thread that uses blocking asynchronous callbacks for processing. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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