JetBrains/rd
图书馆有一个概念
Lifetime
它可以被认为是
AutoCloseable
或
IDisposeable
(见
here
和
here
更多细节)。
最简单的用例示例是这样的smth:
import com.jetbrains.rider.util.lifetime.Lifetime
import com.jetbrains.rider.util.lifetime.onTermination
import java.io.FileInputStream
import java.io.InputStream
class LifetimeExample(lifetime: Lifetime, private val input: InputStream) {
init {
lifetime.onTermination {
input.close()
println("File closed.")
}
}
fun process() {
println("${input.bufferedReader().readText().length} char(s) read.")
}
companion object {
@JvmStatic
fun main(vararg args: String) {
Lifetime.using {
LifetimeExample(it, FileInputStream("/etc/passwd")).process()
}
}
}
}
在这两者中有没有类似的概念
RxJava
或
RxKotlin
?