Skip to content
This repository was archived by the owner on Nov 28, 2019. It is now read-only.
This repository was archived by the owner on Nov 28, 2019. It is now read-only.

Use ZIO's Managed to handle cleaning resources #42

@ghostdogpr

Description

@ghostdogpr

How about using Managed from ZIO to avoid having users (forgetting) invoke close explicitly?

For example:

def apply(): Managed[Exception, AsynchronousServerSocketChannel] =
    IO.syncException(JAsynchronousServerSocketChannel.open())
      .map(new AsynchronousServerSocketChannel(_)).managed(_.close.catchAll(_ => IO.unit))

Then when using it:

AsynchronousServerSocketChannel().use { server =>
 // logic here
}

Or if we want to keep the wrapper API low-level, there could be another higher-level API that does something like that:

SockerServer.start(1337).use { server =>
 // logic here
}

where the acquire operation would create the channel and call bind, and the release operation would close it.

How do you think?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions