Task Groups (creation) design choices of API

As a fun side effect of borrowing pattern matching, you can combine an unconditional if case borrowing pattern match with a _read coroutine to implement scope resource acquisitions in a way that's closer to what Python supports:

struct Resource: ~Copyable {}
var resource: Resource {
  _read {
    print("acquiring")
    yield Resource()
    print("releasing")
  }
}

if case _borrowing r = resource {
  print("using")
}
9 Likes