//#region ../replicache/src/with-transactions.ts
function withRead(store, fn) {
	return using(store.read(), fn);
}
function withWriteNoImplicitCommit(store, fn) {
	return using(store.write(), fn);
}
function withWrite(store, fn) {
	return using(store.write(), async (write) => {
		const result = await fn(write);
		await write.commit();
		return result;
	});
}
/**
* This function takes a promise for a resource and a function that uses that
* resource. It will release the resource after the function returns by calling
* the `release` function
*/
async function using(x, fn) {
	const write = await x;
	try {
		return await fn(write);
	} finally {
		write.release();
	}
}
//#endregion
export { using, withRead, withWrite, withWriteNoImplicitCommit };

//# sourceMappingURL=with-transactions.js.map