3.0 KiB
3.0 KiB
Hints
General
- Read about links and tasks in the official Getting Started guide.
- Take a look at the documentation of the
Task
module. - Read "Demystifying processes in Elixir" on blog.appsignal.com.
- Read "Understanding Exit Signals in Erlang/Elixir" on crypt.codemancers.com.
1. Start a reliability check for a single input
- You don't need a task for this step, a regular linked process is enough.
- There is a built-in function that runs a given anonymous function in a new process and links it to the current process.
2. Interpret the results of a reliability check
- To receive a single message, call
receive
once. It will read the first message that matches any of the given patterns, leaving other messages in the process inbox. - Either a guard or the pin operator can be used to ensure that only messages from a process whose PID matches the PID given to
await_reliability_check_result/2
as an argument will be received. receive
accepts anafter
clause to handle timeouts.
3. Run a concurrent reliability check for many inputs
- The current process must start trapping exits before any new linked processes are spawned.
- Trapping exits in a process is achieved by setting a flag on that process.
- There is a built-in function that sets a flag on a process and returns the old value of that flag.
- The flag for trapping exits is called
:trap_exit
and accepts a boolean value. - Make use of
Enum
functions to first start a process for each input, and then await messages from each process. Use the functions implemented in the two previous steps. Note that the map returned bystart_reliability_check/2
matches the map thatawait_reliability_check_result/2
expects as the first argument.
4. Run a concurrent correctness check for many inputs
- Use an asynchronous task for this step.
- There is a built-in function that starts an asynchronous task.
- There is a built-in function that waits for an asynchronous task to finish executing and returns its result. It accepts a timeout as a second argument.
- Make use of
Enum
functions to first start a task for each input, and then wait for each task.