All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.aws.sdk.kotlin.crt.Closeable.kt Maven / Gradle / Ivy

There is a newer version: 0.8.9
Show newest version
/*
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
 * SPDX-License-Identifier: Apache-2.0
 */

package aws.sdk.kotlin.crt

public interface Closeable {
    /**
     * Close this resource
     */
    public fun close()
}

public inline fun  C.use(block: (C) -> R): R {
    var closed = false

    return try {
        block(this)
    } catch (first: Throwable) {
        try {
            closed = true
            close()
        } catch (second: Throwable) {
            // suppressed
        }

        throw first
    } finally {
        if (!closed) {
            close()
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy