#Basic Concurrency Question

1 messages · Page 1 of 1 (latest)

hybrid spruce
#

I was noodling around with some simple code and noticed that the following executes out of procedural order, e.g. "the end" sometimes prints in the middle of the list.each execution. Can you help me understand why that is?

import gleam/io
import gleam/list

pub fn main() {
  let my_name = "Bob"
  io.println("Hello " <> my_name <> "! Welcome to the Gleam world.")
  let my_list = [1, 2, 3, 4, 5]
  list.each(my_list, fn(x) { io.debug(x) })
  io.println("This is the end, my friend.")
}
pseudo snow
#

as far as I know stdout is non blocking and not necessarily synchronous

cyan elk
#

io.debug uses stderr, while io.println uses stdout, so they can sometimes come through in different orders.

#

If you need them to come through in a consistent order, you can use io.println with string.inspect, which returns the string representation of any Gleam value

#

Your code here isn't doing anything concurrent.

hybrid spruce
#

cool - thanks

patent yoke