HarlonWang / quickjs-wrapper

QuickJS wrapper for Android/JVM
Apache License 2.0
169 stars 30 forks source link

[Feature Request] Make QuickJsContext implement Closeable #64

Closed dgmltn closed 2 months ago

dgmltn commented 8 months ago

Thank you so much for this library 🙏 ! I have an easy suggestion for improvement:

It would be pragmatic to be able to use QuickJSContext with try-with-resources (in Java) or .use (in Kotlin), like this:

try (QuickJSContext context = QuickJSContext.create()) {
    ...
}
QuickJSContext.create().use { context ->
    ...
}

But that requires an object that implements Closeable. This should be as simple as adding this method to QuickJsContext:

public void close() {
    destroy()
}
HarlonWang commented 8 months ago

ok, I will add it in the next version.