Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[refactor/use-extension-function] Refactor 'getImageSize' function #63

Merged
merged 2 commits into from
Feb 7, 2024

Conversation

l2hyunwoo
Copy link
Collaborator

  • use 'use' extension function to release resource safe
@InlineOnly
public inline fun <T : Closeable?, R> T.use(block: (T) -> R): R {
    contract {
        callsInPlace(block, InvocationKind.EXACTLY_ONCE)
    }
    var exception: Throwable? = null
    try {
        return block(this)
    } catch (e: Throwable) {
        exception = e
        throw e
    } finally {
        when {
            apiVersionIsAtLeast(1, 1, 0) -> this.closeFinally(exception)
            this == null -> {}
            exception == null -> close()
            else ->
                try {
                    close()
                } catch (closeException: Throwable) {
                    // cause.addSuppressed(closeException) // ignored here
                }
        }
    }
}

@onseok
Copy link
Owner

onseok commented Feb 7, 2024

LGTM, thanks @l2hyunwoo for the use extension function enhancement! 👍

@onseok onseok merged commit 352a1ab into onseok:main Feb 7, 2024
2 checks passed
@l2hyunwoo l2hyunwoo deleted the feature/refactor-resize-function branch February 7, 2024 12:33
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants