juan_gandhi: (VP)
Juan-Carlos Gandhi ([personal profile] juan_gandhi) wrote2014-05-16 05:32 pm
Entry tags:

code critique?

Guys, I do appreciate your opinions a lot.

  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.

[identity profile] thedeemon.livejournal.com 2014-05-17 04:54 am (UTC)(link)
Я думал там опечатка просто ("our" vs. "your").
Edited 2014-05-17 05:03 (UTC)

[identity profile] ivan-gandhi.livejournal.com 2014-05-17 05:11 am (UTC)(link)
omfg; да, опечатка. Так и живем, блин.