From 96196d1e174b1bea6782bbd9064131f823c05c17 Mon Sep 17 00:00:00 2001 From: Alexey Kasyanchuk Date: Mon, 9 Jan 2017 17:23:49 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B1=D0=BE=D0=BB=D0=B5=D0=B5=20=D0=BC=D0=B0?= =?UTF-8?q?=D1=81=D1=88=D1=82=D0=B0=D0=B1=D0=B8=D1=80=D1=83=D0=B5=D0=BC?= =?UTF-8?q?=D0=BE=D0=B5=20=D0=BE=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D1=80=D0=B0=D0=B7=D0=B4=D0=B0=D1=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/recent-torrents.js | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/recent-torrents.js b/src/recent-torrents.js index 139d078..a9815a9 100644 --- a/src/recent-torrents.js +++ b/src/recent-torrents.js @@ -177,12 +177,24 @@ export default class RecentTorrents extends Component { this.forceUpdate(); } - this.displayNewTorrent = setInterval(() => { - if(this.displayQueue.length == 0) - return; + this.displayNewTorrent = () => { + if(!this.displayNewTorrent) { + return; + } - if(this.state.pause) + if(this.displayQueue.length == 0) { + setTimeout(this.displayNewTorrent, 1000); return; + } + + let speed = 850 - (((this.displayQueue.length / 100)|0) * 100) + if(speed < 10) + speed = 10; + + if(this.state.pause) { + setTimeout(this.displayNewTorrent, speed); + return; + } let torrent = this.displayQueue.shift(); this.torrents.unshift(torrent); @@ -192,7 +204,9 @@ export default class RecentTorrents extends Component { } this.forceUpdate(); - }, 850); + setTimeout(this.displayNewTorrent, speed); + } + this.displayNewTorrent(); }); this.newTorrentFunc = (torrent) => { this.displayQueue.push(torrent); @@ -221,7 +235,7 @@ export default class RecentTorrents extends Component { if(this.tracketUpdate) window.torrentSocket.off('trackerTorrentUpdate', this.tracketUpdate); if(this.displayNewTorrent) - clearInterval(this.displayNewTorrent); + delete this.displayNewTorrent; } render() { if(!this.torrents || this.torrents.length == 0)