Working with MVar
In this recipe, we will look at MVar and Chan as the basic ingredients of a concurrent pipeline. We will create a Forex Order processing system, in which the orders to buy or sell currency are sent to an exchange. The exchange backend will process the orders, and print the summary.
How to do it...
- Create a new project called
working-with-mvar
with thesimple
stack template:
stack new working-with-mvar simple
- Add dependencies on the
containers
andrandom
libraries in thebuild-depends
sub-section of theexecutable
section. Also add the-threaded
option to theghc-options
subsection:
executable working-with-mvar hs-source-dirs: src main-is: Main.hs ghc-options: -threaded default-language: Haskell2010 build-depends: base >= 4.7 && < 5 , containers , random
- Open
src/Main.hs
. We will be adding our source here. Define...