Skip to Content
Mastering Functional Programming
book

Mastering Functional Programming

by Anatolii Kmetiuk
August 2018
Intermediate to advanced
380 pages
10h 2m
English
Packt Publishing
Content preview from Mastering Functional Programming

Asynchrony

Remember when we discussed IO, we stressed the importance of asynchrony and non-blocking computations? Threads of the underlying operating system are scarce, and on a system with high load, you need to utilize them well. Blocking is not a wise utilization of the threads.

We have discussed that you should not invoke other threads from the current actor. The motivation for this is to prevent access to the mutable state of the current actor from more than one thread. We have discussed that whenever we need to process something, we schedule the processing as a message to the current actor.

Therefore, to enforce single-threaded processing, you might be tempted to block on a future from a message-handling logic, as follows:

Await.ready(future, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning Functional Programming

Learning Functional Programming

Jack Widman

Publisher Resources

ISBN: 9781788620796Supplemental Content