What does transaction(block:) actually do?

I'm working on an app where I want to add a large amount of data to SwiftData, but roll back if any errors occur during this process. SwiftData has a method called transaction (linked below), but it does not have any documentation and I can't find any info about it online. What does it actually do?

https://developer.apple.com/documentation/swiftdata/modelcontext/transaction(block:)

What does transaction(block:) actually do?
 
 
Q