Skip to content

On using Using #592

Closed
Closed
@julienrf

Description

@julienrf

@NthPortal has recently put a nice effort (scala/scala#6907 and scala/scala#7468) to provide a resource safety system to the scala-library.

I think this is a great step forward but I do have some concerns about including it in the scala-library in its current form:

  • It only works for synchronous execution paths,
  • It introduces a Releasable typeclass with only one instance, java.lang.AutoCloseable (thus, it looks like a premature abstraction, unless we have other possible instances in mind?),
  • It hasn’t been tested a lot in the wild.

So, although I completely agree that supporting AutoCloseable is useful, I think we should wait for the proposed design to have been proven successful before including it in the scala-library. I would suggest instead incubating it as a separate library (for instance scala-autocloseable).

Last but not least, I think it would be extremely valuable to provide a resource safety system in the scala-library but it should have a larger applicability: it should also support asynchronous execution paths. For the record, this is something that libraries like Monix or scalaz-zio do support. When Future was introduced to the standard library 6 years ago that was a huge step forward, but we’ve seen room for improvement over time: it’s too easy to leak CPU resources by mistake (e.g. Future.firstCompletedOf(aLongComputation() :: anotherLongComputation() :: Nil) continues running the longest computation even after the first one has completed). In my opinion, this is an important problem that we should address.

I’m not sure how much time we have before 2.13.0-RC1 but I think we should allocate some research work to properly support asynchronous execution paths before commiting to a design. If it’s too late, then I would suggest moving the current Using abstraction to a separate library so that we can provide a nice, solid and polyvalent resource safety system in Scala 2.14.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions