我正在玩 ZIO ,并构建了一个简单的应用程序,可通过HTTP获取内容:
for {
options <- Options.parse(args)
http = HttpClient(args)
content <- Download.execute(args.resource).provide(http)
} yield ()
它可以完成工作,但是客户端得到 Play StandaloneWsClient 的支持,我想按照文档https://github.com/playframework/play-ws#scala-1
中的说明关闭它并终止actor系统。所以我创建了一个finalizer方法,但似乎没有效果:
// ...
content <- Download.execute(args.resource).ensuring(http.disconnect()).provide(http)
// ...
class HttpClient {
// ...
def disconnect():UIO[Unit] = ZIO.effectTotal {
client.close()
system.terminate()
}
如何指示ZIO调用finalizer方法释放资源?