parallel_output_order: printing from inside a parallel call

List.pmap, Parallel.pmap and the rest of the parallel family call your function on many elements at the same time. A println (or print, print_line, print_stderr) inside that function runs whenever its call does, so the lines come out in whatever order the calls happen to run, and the order can change from one run to the next.

The warning also fires when the function calls a helper in the same module that prints, and when the function passed is a named function of this module that prints.

Other I/O inside a parallel call (an HTTP request per element, a file read) is what the parallel functions are for, and draws no warning.

A program that triggers it

mod Main do
  needs IO.Console
  needs IO.Spawn

  fn main(_c : Cap(IO.Console), _s : Cap(IO.Spawn)) do
    let _ = List.pmap([1, 2, 3], fn x -> println("item " ++ int_to_string(x)))
    ()
  end
end

The fix

Return the text from the function and print it after the parallel call. The results come back in input order, so the output is the same every run:

mod Main do
  needs IO.Console
  needs IO.Spawn

  fn main(_c : Cap(IO.Console), _s : Cap(IO.Spawn)) do
    let lines = List.pmap([1, 2, 3], fn x -> "item " ++ int_to_string(x))
    List.each(lines, fn l -> println(l))
  end
end