Skip to content

Instantly share code, notes, and snippets.

View arnolddevos's full-sized avatar

Arnold deVos arnolddevos

  • Background Signal Pty Ltd
  • Sydney, Australia
View GitHub Profile
@arnolddevos
arnolddevos / Barrier.scala
Last active February 24, 2021 01:16
Easy concurrency primitives
// take() blocks until next* offer()
// (similar but not the conventional meaning of barrier)
def barrier() = new Gate[Unit, Long] {
private val state = new Transactor(0l)
val take =
for {
v0 <- state.transact(v => Observed(succeed(v)))
v1 <- state.transact { v =>
if(v > v0) Observed(succeed(v))