Uploaded image for project: 'Ruby Driver'
  1. Ruby Driver
  2. RUBY-2165

Yield client to block from constructor

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor - P4
    • Resolution: Fixed
    • None
    • 2.13.0.rc1
    • Dev Exp
    • Fully Compatible

    Description

      When using Ruby driver to manage the server deployment, there is often a need to create a client for a particular operation. Currently this requires a begin-ensure block to close the client:

            client = Mongo::Client.new(...)
            begin
              client.database.command(ismaster: 1)
            ensure
              client.close
            end
      

      Instead it would be convenient to have the constructor yield to the provided block and close the client, so that the application code looked like this:

      Mongo::Client.new(...) do |client|
        client.database.command(ismaster: 1)
      end
      

      The constructor already yields self if a block is given, but does not close the client resulting in the client leak if the application actually used the pattern given above. Also this usage is not documented in https://docs.mongodb.com/ruby-driver/current/quick-start/ (which is additionally entirely silent on the need to close the client).

      Attachments

        Issue Links

          Activity

            People

              neil.shweky@mongodb.com Neil Shweky (Inactive)
              oleg.pudeyev@mongodb.com Oleg Pudeyev (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: