Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix timeRemaining issue #549

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

Fix timeRemaining issue

When the swarm hasn't been created but the timeRemaining property is accessed, it causes an error.
  • Loading branch information
DiegoRBaquero committed Dec 30, 2015
commit efc4b54f1ec3aa5cd0e2f60da74a67049f70de44
@@ -97,7 +97,7 @@ function Torrent (torrentId, opts) {
Object.defineProperty(Torrent.prototype, 'timeRemaining', {
get: function () {
if (this.done) return 0
if (this.swarm.downloadSpeed() === 0) return Infinity
if (this.swarm === undefined || this.swarm.downloadSpeed() === 0) return Infinity

This comment has been minimized.

Copy link
@feross

feross Jan 1, 2016

Member

This would also fail if swarm is null. It's better to just to do:

if (!this.swarm || this.swarm.downloadSpeed() === 0) return Infinity
else return ((this.length - this.downloaded) / this.swarm.downloadSpeed()) * 1000
}
})
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.