Make sure we hold the same conn for listen forever
Stephen Paul Weber
created
hold by itself will never cut it, because we use EM timers inside to
break the connection even to the promise, so we can't sync on that.
Since we really do want to essentially leak this connection for the life
of the process, then let's do that directly.
@@ -10,6 +10,13 @@ class Postgres < SimpleDelegator
})
end
+ # WARNING: this uses up a connection from the pool which never releases
+ # Use it only if you need the same connection for the life of the process
+ def acquire
+ conn = __getobj__.send(:acquire, Fiber.current) until conn
+ conn
+ end
+
def query_one(sql, *args, field_names_as: :symbol, default: nil)
query_defer(sql, args).then do |rows|
rows.field_names_as(field_names_as)&.first || default