Created
May 17, 2016 20:08
-
-
Save arthurnn/a449f1aebe302fed29bea07b60276e0b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'pg' | |
class Context | |
attr_reader :connections | |
def initialize | |
@connections = {} | |
end | |
def connection | |
@connections.fetch(Process.pid) { @connections[Process.pid] = PG.connect( dbname: 'test' ) } | |
end | |
end | |
context = Context.new | |
p context.connection.exec( "SELECT current_database();" ).to_a | |
parent_pid = Process.pid | |
fork do | |
at_exit do | |
IO.for_fd(context.connections[parent_pid].socket).close | |
end | |
end | |
Process.wait | |
p context.connection.exec( "SELECT current_database();" ).to_a |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment