|
|
|
|
|
by runT1ME
4414 days ago
|
|
How does asynchronous futures end up being more complicated or in any way worse than the blocking threaded approach? for {
user <- asyncGetUser(1)
company <- asyncGeCompany(user.companyid)
longresult <- asyncProcess(company.getSomething)
} yield longresult
|
|
It can be a problem. In Akka actors, referencing sender() from a future will be unpredictable because sender() could've changed in the mean time.
I think there are three strong solutions which address this problem:
1) Immutable state. Solves this problem completely but accidental capture remains an issue.
2) Hiding mutable state within actors. I hesitate to present this as a general solution though since it really requires going all-in with actors (I don't consider that to be a bad thing, necessarily).
3) Projects like Scala Spores [1] aim to tackle this at the compiler by capturing mutable references and executing async closures in an immutable environment and prohibiting accidental capturing. IOW, turning accidental capture into a compiler error. I'm excited about this one.
[1] https://speakerdeck.com/heathermiller/spores-distributable-f...