How about using `Managed` from ZIO to avoid having users (forgetting) invoke `close` explicitly? For example: ```scala def apply(): Managed[Exception, AsynchronousServerSocketChannel] = IO.syncException(JAsynchronousServerSocketChannel.open()) .map(new AsynchronousServerSocketChannel(_)).managed(_.close.catchAll(_ => IO.unit)) ``` Then when using it: ```scala 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: ```scala 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?
How about using
Managedfrom ZIO to avoid having users (forgetting) invokecloseexplicitly?For example:
Then when using it:
Or if we want to keep the wrapper API low-level, there could be another higher-level API that does something like that:
where the
acquireoperation would create the channel and call bind, and thereleaseoperation would close it.How do you think?