Future, akka-stream, scalaz-stream

前半はFutureやExecutionContextの話で、 後半はdjspiewakさんが 「akka-streamはpushでscalaz-streamはpullモデルだ」 と発表したことに関してviktorklangさんが「そうじゃない」というところから議論始まってるのがポイント 続きを読む
2
Daniel Spiewak @djspiewak

@viktorklang Haven’t seen it. Is there video somewhere?

2014-09-20 09:19:23
Lgd. Viktor Klang @viktorklang

@djspiewak Sadly no. Watching mine and Roland's ScalaDays 2014 talk will give most of the explanation though.

2014-09-20 09:21:28
Lgd. Viktor Klang @viktorklang

@djspiewak at youtube.com/watch?feature=… you are assuming that ECs aren't trampolinable. scalaz.Task seem to hog current Thread during eval?

2014-09-20 09:23:57
Daniel Spiewak @djspiewak

@viktorklang It doesn’t have to hog the current thread (runAsync is the not-selfish one). I don’t use run very often though (just endpoints)

2014-09-20 09:26:00
Daniel Spiewak @djspiewak

@viktorklang Task does use the same thread as you flatMap through though. This achieves much higher efficiency and thread utilization.

2014-09-20 09:26:39
Daniel Spiewak @djspiewak

@viktorklang You can kick a Task into a different thread pool using Task.apply instead of delay.

2014-09-20 09:27:04
Lgd. Viktor Klang @viktorklang

@djspiewak Yes, and it will still hog a thread in that threadpool until full eval? Using trampolining you can tune fairness vs throughput.

2014-09-20 09:31:24
Daniel Spiewak @djspiewak

@viktorklang Yes, that’s the tradeoff. You can kick back to the executor explicitly using Task.fork, but it is explicit.

2014-09-20 09:32:04
Daniel Spiewak @djspiewak

@viktorklang I think this is a reasonable tradeoff given that Task users tend to flatMap a lot more with much smaller units.

2014-09-20 09:32:33
Lgd. Viktor Klang @viktorklang

@djspiewak IMO ECs give the best of both worlds, and does not rely on the user to fiddle with the demarcation. github.com/scala/scala/bl…

2014-09-20 09:35:48
Daniel Spiewak @djspiewak

@viktorklang This is true, but then you have to pass the EC around everywhere and you lose abstraction over the monad.

2014-09-20 09:36:54
Lgd. Viktor Klang @viktorklang

@djspiewak And you did not tell us?! Thanks "buddy"! @runarorama and I are now watching @strangeloop_stl from a distance :(

2014-09-20 09:36:59
Lgd. Viktor Klang @viktorklang

@djspiewak I think I'll regret saying this but I guess you could have an ExecutionContext monad transformer…

2014-09-20 09:38:30
Daniel Spiewak @djspiewak

@viktorklang LOL. You sort of could. More likely, you would wrap Future to have a real flatMap and carry a “current” EC along for the ride.

2014-09-20 09:39:35
Daniel Spiewak @djspiewak

@viktorklang Scalaz does define a monad for Scala’s Future, but it misses out on some features (like changing ECs).

2014-09-20 09:41:32
Lgd. Viktor Klang @viktorklang

@a4dev Super simple: (implicit ec: ExecutionContext), add it to all methods w. Futures, pass EC in at the end of the world. /cc @djspiewak

2014-09-20 10:31:13
Daniel Spiewak @djspiewak

@viktorklang @a4dev Unless you have methods that manipulate futures via abstractions and don’t know about EC.

2014-09-20 10:33:10
Lgd. Viktor Klang @viktorklang

@djspiewak I chucked when you mentioned Netty and handshakes. (from one who also lived to tell the tale) :)

2014-09-20 10:34:37
Daniel Spiewak @djspiewak

@viktorklang @a4dev The traverse function in Scalaz. Or really anything that uses Monad (or its ancestry).

2014-09-20 10:34:59
Daniel Spiewak @djspiewak

@viktorklang Netty handshakes are amazingly bad. I didn’t even realize software could be so awful…

2014-09-20 10:35:30
Daniel Spiewak @djspiewak

@viktorklang It sure is pretty with the streams interface though. A handshake is just another step in the for comprehension.

2014-09-20 10:35:55
Lgd. Viktor Klang @viktorklang

@djspiewak Sounds like a library-induced limitation ;-) /cc @a4dev

2014-09-20 10:36:55