1. 19
  1.  

  2. 6

    Huh, so looks like crossbeam-channel is a successor to chan. Good to know.

    It’s interesting that even with Rust’s minimal standard library, there’s a bit of a “urllibN” situation with the concurrency stuff, with crossbeam-* and parking_lot :)

    1. 3

      Minor correction in one example:

      use crossbeam_channel as channel;
      
      // Create a non-buffered channel.
      let (tx, rx) = channel::unbounded();
      
      // Create a buffered channel with a capcity of one.
      let (s, r) = channel::bounded(1);
      
      [...]
      

      The first comment should be Create a buffered channel of unlimited capacity.. As you explain above this point, it would have to block when you send if it were unbuffered.

      1. 1

        Do you mean this with regard to the Go example? I think you’re right though and I’ll make that fix later.

        1. 1

          I meant in the first crossbeam-channel example.

      2. 2

        One of the biggest griefs in Go is that channels and IO are not composable in a select statement. For example this is not possible:

        select {
        case msg := <-myChan:
        case msg := <-myFile.Read():
        }
        

        Instead, the file reader has to be wrapped in a goroutine and then forwarded to a channel. Then make sure to handle the file closing and shutdown the goroutine properly. I am aware that there are implementation details that make this difficult but since Go went to the trouble of implementing the NxM multiplexing, it’s a missed opportunity to make communication patterns very simple.