yruslan / channel_scala

Scala implementation of the concurrency primitive similar to GoLang channels.
Apache License 2.0
8 stars 0 forks source link

Align `select()` behavior to match GoLang #22

Closed yruslan closed 9 months ago

yruslan commented 10 months ago

Describe the feature

In Go a select() statement that uses the same synchronous channel in a single thread will fail on the deadlock. In Scala channels implemented in this project, the code won't block, and also the send will transfer the value, but the receiver won't be triggered until another such call.

Here is an example:

val channel = Channel.make[Int]

select(
  channel.recver(n => {
    println(s"Received $n")
  }),
  channel.sender(10) {
    println("Sent 10")
  }
)

Scala code will print "Sent 10", GoLang equivalent code will fail on deadlock.

Since Scala does not have deadlock checkers, it should just deadlock in this case.