Created
May 17, 2016 20:06
-
-
Save arthurnn/40c5b812411af5e02e73644992c9f3b1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
context.connections[parent_pid].socket_io.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