exercism/elixir/rpn-calculator-inspection/HINTS.md

3.0 KiB

Hints

General

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 an after 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 by start_reliability_check/2 matches the map that await_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.