Apart from escrow services mentioned by @tylerl, there are cryptographic protocols called fair exchange protocols which try to achieve this property. See this page for a list of references to relevant research articles.
Most fair exchange protocols do something like this:
- The two data items to be exchanged are encrypted, with zero-knowledge proofs that the encryption was done properly. The two keys Ka and Kb have size n bits.
- The two keys are exchanged one bit at a time: Alice send first bit of Ka to Bob, Bob sends first bit of Kb to Alice, Alice sends second bit of Ka to Bob, and so on.
- If one of the parties bails out before protocol completion, the computational effort needed to complete the partially obtained keys are similar for Alice and Bob (hence the "fairness").
These protocols are highly technical because they need strong ZK proofs that what they send is "correct". If Alice intends on bailing out, she could also try to send junk bits to Bob and thus gain an unfair advantage. Mathematics are involved. There are also variants which try to account for an asymmetry in computing power (if Alice has a 20-PC cluster and Bob has only a smartphone, Alice may want to close the connection earlier). To my knowledge, none of these protocols have reached the "standardized and implemented as an easy-to-use library" stage.