concurrency - When could Futures be more appropriate than Actors (or vice versa) in Scala? -


suppose need run few concurrent tasks.

i can wrap each task in future , wait completion. alternatively can create actor each task. each actor execute task (e.g. upon receiving "start" message) , send result back.

i wonder when should use former (with futures) , latter (with actors) approach , why future approach considered better case described above.

because syntactically simpler.

val tasks: seq[() => t] = ??? val futures = tasks map {   t => future { t() } } val results: future[seq[t]] = future.sequence(futures) 

the results future can wait on using await.result or can map further/use in for-comprehension or install callbacks on it.

compare instantiating actors, sending messages them, coding receive blocks, receiving responses them , shutting them down -- require more boilerplate.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

javascript - addthis share facebook and google+ url -

ios - Show keyboard with UITextField in the input accessory view -