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

jvmMain.extensions.MongoClient.kt Maven / Gradle / Ivy

There is a newer version: 0.27.0
Show newest version
package io.fluidsonic.raptor.mongo

import com.mongodb.*
import io.fluidsonic.mongo.*


public suspend inline fun MongoClient.transaction(
	options: TransactionOptions = TransactionOptions.builder().build(),
	block: (session: ClientSession) -> Unit,
) {
	startSession().use { session ->
		session.startTransaction(options)

		try {
			block(session)
		}
		catch (e: Throwable) {
			session.abortTransaction()
			throw e
		}

		session.commitTransaction()
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy