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 04:03 am (UTC)We appreciate ours too. ;)
(no subject)
From:(no subject)
From:(no subject)
From:no subject
Date: 2014-05-17 04:57 am (UTC)if not using the Akka actors.
(no subject)
From:(no subject)
From:(no subject)
From:(no subject)
From:(no subject)
From:(no subject)
From:(no subject)
From:no subject
Date: 2014-05-17 08:08 am (UTC)Вот про такое место вы знаете?
http://codereview.stackexchange.com
Мне интересно читать такие посты, не подумайте, просто там заведомо шире аудитория.
(no subject)
From:no subject
Date: 2014-05-18 12:11 am (UTC)If there are N files to upload, start N asynchronous upload tasks; the continuation for each task should check the result and update the corresponding item in the collection of N results. After all the N tasks are started, call asynchronous wait_all/when_all for the collection of the started tasks.
Bonus point if the platform's library provides an asynchronous implementation of HTTP POST: it's naturally IO-bound so shouldn't block any threads. Double-bonus if it supports cooperative cancellation.
This pattern is first-class citizen in C#/.NET these days with full library support of asynchronous I/O functions and compiler support for automatic code rewriting into continuation-passing style for asynchrony. There should be something for Scala too (first link of https://www.google.com/search?q=async+await+scala seems relevant).
(no subject)
From:(no subject)
From:(no subject)
From:(no subject)
From: