Welcome back to the sixth part of my blog series on concurrent programming in fsharp. In this part, we are going to learn how to deal with state changes while doing concurrent programming through a fun example.
Time Bomb Simulator The example that we are going to see is a time bomb simulator. The time bomb transitions through different states as shown below during its lifecycle.
The associated fsharp type TimeBomb will have the following signature
In the last blog post, we learned how Alt in Hopac works and its applications. In this blog post, we are going to apply what we learned so far by creating a Ticker.
Using ticker we can do something repeatedly at regular intervals.
To implement a Ticker in Hopac, we have to know one more abstraction in Hopac called IVar. So, in the first section, we are going to learn IVar and then we'll use it to implement Ticker.
Welcome back to the fourth part of Concurrent Programming in fsharp blog post series. In part-2, we just learned that Alt<'a> is a subclass of Job<'a>. In this blog post, we are doing to dive deep into this abstraction and learn what it brings to the table.
An Example Before diving into the definition of Alt<'a>, let's figure out why we need it in the first place.
Assume that we have a function delayedPrintn which prints a given message after n milliseconds
Two years back, I wrote a blog post on how to implement the API Gateway pattern using Reactive Extensions(Rx). In this third part of concurrent programming in fsharp using Hopac blog series, we are going to revisit that blog post and port it to use Hopac instead of Reactive Extensions.
Rx vs Hopac The critical difference between Rx and Hopac is their communication model.
Rx is primarily a system for querying data in motion asynchronously, and systems built using Rx rely on asynchronous message-passing.
In the last blog post, we learned the how to create jobs and run them parallelly using Hopac. In this second part of the blog post series, we are going to explore inter-job communication.
Share Memory By Communicating In multi-threaded programming model, if two threads want to communicate, the typical approach is using a shared memory backed by locks, thread-safe data structures (or other synchronisation primitives). We have to follow specific best practices to avoid Deadlocks and Race Conditions while using the shared memory approach.