3 ms·
> If you think actors, futures, and async/await are so great, imagine having to write every single function invocation in that manner. I don't see how: v
by apta 8y ago
> If you think actors, futures, and async/await are so great, imagine having to write every single function invocation in that manner.
I don't see how:
val f = Future { foo() }
// do work...
f match {
case Success(res) => useRes(res)
case Failure(error) => handleError(error)
}
Is any more difficult than:
done := make(chan bool)
var res int
go foo(done, &res)
<-done
useRes(res)
As a matter of fact, the first one is much easier. I don't have to create and pass a channel, and manually handle returning a success or failure. The first approach is much better
- wahern 8y agoYou're not understanding (or at least not appreciating) the function color problem mentioned in the article. See, e.g., http://journal.stuffwithstuff.com/2015/02/01/what-color-is-your-function/ http://journal.stuffwithstuff.com/2015/02/01/what-color-is-y...
- apta 8y agoI read that article before. Here's the thing, the only thing that the "go" keyword makes easier is having the ability to have any arbitrary function run in a green thread without having to modify it's signature. However, the moment you want to actually do something useful with it (e.g. communicate with it, cancel it, or read its returned value), you're going to have to pass a channel (or more) or a waitgroup to it anyway, modifying its signature and changing its "color". The issue remains pretty much the same.