-
Type: Improvement
-
Resolution: Fixed
-
Priority: Minor - P4
-
Affects Version/s: None
-
Component/s: Dev Exp
-
2
-
Fully Compatible
client.with_session do |session| .... end
So that the session can be closed after the block completes.
We already have the with_session method but it appears to be private. I suggest changing start_session to optionally take a block.
Requirements:
Make start_session take a block, or verify this already happens.
Add tests if needed for start_session with block.
Add tests if needed for start_session with block where the block raises an exception, asserting the exception is propagated and the session is closed.
Add a usage example to https://docs.mongodb.com/ruby-driver/master/tutorials/ruby-driver-sessions/. I suggest taking the first example in the section dealing with start_session, transforming it to use the block form, and making that the first example; then retaining the existing non-block form example as alternate way of using sessions.