code critique?
May. 16th, 2014 05:32 pm![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
Guys, I do appreciate your opinions a lot.
What happens here: we upload until we are out of patience with a streak of bad luck, probably meaning the server is dead.
val patience = 10 case class UploadProgress(uploaded: Set[File] = Set.empty, failed: Set[Result[File]] = Set.empty, badLuckStreak: Int = 0) { def errors = Result.traverse(failed) def +(file:File) = { if (badLuckStreak > patience) this else { uploadOneFile(file) match { case Good(file) => UploadProgress(uploaded + file, failed, 0) case bad => UploadProgress(uploaded, failed + bad, badLuckStreak + 1) } } } } def uploadScheduledFiles():UploadProgress = { if (!client.isAlive) UploadProgress(Set.empty, Set(Result.error("Upload server is dead, sorry")), 0) else { (UploadProgress() /: listFilesForUpload)(_ + _) } }
What happens here: we upload until we are out of patience with a streak of bad luck, probably meaning the server is dead.
no subject
Date: 2014-05-17 03:24 pm (UTC)