I have written a JavaScript function that I am not sure how to test, so I will just ask - Is this correct JavaScript (formatting aside)?
function remember($miner,quality,equals){
var for24hrs=new Date().getTime()+86400000;
G.pool.miners[$miner]=(!G.pool.miners[$miner])?{}:G.pool.miners[$miner];
if(quality!=='conn'){
G.pool.miners[$miner][quality]=equals;
G.pool.miners[$miner]['remain']=for24hrs;
}
for(var miner in G.pool.miners){
if(G.pool.miners[miner].remain < new Date().getTime()){
G.pool.miners[miner]=null;
}
}
return;}
The code saves a record of a connected socket (miner) on the node.js sever when ever the miner changes state. The server will remember the miner for 24hrs after. Another miner may change state and become remembered - when this happens if the first miner has not changed state in 24hrs the first miner will be destroyed.
The only time I dont wan't to remember them is when they are first connected
(quality==='conn')
It may be called like this:
remember('miner_bob','likes to dig',true);
remember('miner_bob','eats','sandwiches');
remember('miner_jim','likes to dig',false);
remember('miner_jim','eats','road kill');
G, G.pool, and G.pool.miners are all objects:
G is on the global scope to make pool accessible
G.pool has values and functions
G.pool.miners is the place to store miners in memory
Did I make any mistakes?