Juan-Carlos Gandhi (
juan_gandhi) wrote2014-05-16 05:32 pm
![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
Entry tags:
code critique?
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
We appreciate ours too. ;)
no subject
no subject
no subject
no subject
if not using the Akka actors.
no subject
But actually, I was planning to just have a parallel collection; is not it enough?
Also, judging by the iq level of the server, I've abandoned the idea of sending all of them in one fell swoop, in one request.
no subject
no subject
no subject
no subject
no subject
But as first draft step IMHO it isn't so bad :) Further it always can be improved more.
no subject
So instead of create whole bunch of task it better would create some stream of chunks with them.
IMHO.
no subject
Вот про такое место вы знаете?
http://codereview.stackexchange.com
Мне интересно читать такие посты, не подумайте, просто там заведомо шире аудитория.
no subject
no subject
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
The problem is, I have to stop them all if n report failure... well, is it a problem? Probably not.
no subject
no subject
no subject