
我做了一个小玩具,在 vps 上做一个下载中转的。 nodejs 连接 rpc ,然后用的是 aria2 这个库。问题就是它会产生多次的(每次加1个) onDownloadCompelte 事件。
Download.prototype.init = function() { aria2 = new Aria2({ host: 'localhost', port: 6800, secure: false, secret: '', path: '/jsonrpc' }); _onDownloadStart(); _onDownloadComplete(); } Download.prototype.dl = fn; .... var Down = new Download(); ....很多行 if(method== 'post') { Down.dl() } 每次路由就调一次 Down.dl 方法,产生一次 start 和 Complete ,但不知道为什么从第二次下载开始就会触发多次的 start 和 complete 。我看了 arai2 这个 npm 包,它没有实现这 2 个事件,貌似是由 rpc 这个对象返回的,那是 arai2 程序本身的问题?