Chapter 6: Concurrency
In some scenarios, a program might need to handle the processing of multiple chunks of work, such as summing the number of lines in a series of files. This is a perfect example of the type of problem that Concurrency can help to solve by allowing the program to execute chunks of work while waiting on others. In this chapter, we will learn how concurrency works in Crystal and cover the following topics:
- Using fibers to complete work concurrently
- Using channels to communicate data safely
- Transforming multiple files concurrently
By the end of this chapter, you should be able to understand the differences between concurrency and parallelism, how to use fibers to handle multiple concurrent tasks, and how to use channels to properly share data between fibers. Together, these concepts allow for the creation of programs that can multitask, resulting in more performant code.