NodeJS setInterval()无法正常工作

时间:2015-04-15 20:59:11

标签: javascript node.js bitcoin bitcore

一段时间后,程序不会在setInterval()方法中调用console.log(infos)。它在几分钟后继续工作,但是间隔值与设定值不同,例如。如果我将间隔设置为200ms,它将在10分钟或更长时间后调用console.log(infos)。我做错了什么?这是我的代码

var bitcore = require('bitcore');
var p2p = require('bitcore-p2p');
var Peer = p2p.Peer;
var Pool = p2p.Pool;
var Networks = bitcore.Networks;
var messages = new p2p.Messages();
peer = new Peer('127.0.0.1', 8333);
pool = new Pool(Networks.livenet);
pool.connect();

var  Infos = [],

process.nextTick(function(){
    setInterval(function(){
    console.log(Infos);
    Infos = [];
} , 200);
});

pool.on('peerinv', function (peer, message) {
peer.sendMessage(messages.GetData(message.inventory));
peer.on('tx', function (tx) {
var transaction = tx.transaction;
console.log(transaction.id);
Infos.push({ "txId" : transaction.id });
})
});

0 个答案:

没有答案