go · level 3 check

a concurrent job runner.

Time to ship a real tool! `jobrun` reads a list of jobs, runs them on a pool of workers and prints a tidy report. The first line of input says how many workers to use. Every other line is a job: a name and how many milliseconds it takes, such as `build 30`.

Inside, `NewRunner` takes functional options, `Run` feeds the jobs to the workers through a channel, and a closer goroutine closes the results once every worker is done. Each job gets its own context with a timeout of 100 milliseconds, so a job that takes too long is stopped and reported as `timed out`.

A shipped tool is polite about bad input: it skips blank lines, explains every line it cannot read, and refuses a worker count that is not a positive number. Workers finish in any order, so the report is sorted by name. Fill in each `____`, then try your own job lists.

Fill in every ____ then run the checks.
  1. 1 It runs every job and sorts the reportuses: worker pools
  2. 2 It stops a slow job on timeuses: context timeouts
  3. 3 It skips bad lines and says whyuses: handling bad input
  4. 4 It refuses a bad worker countuses: handling bad input
  5. 5 It copes with no jobs at alluses: closing channels
  6. 6 It keeps the order fixed with one worker and repeated namesuses: sorting results

Take as long as you like and try as many times as you want.