summaryrefslogtreecommitdiffstats
path: root/lem/postgres/queued.lua
diff options
context:
space:
mode:
Diffstat (limited to 'lem/postgres/queued.lua')
-rw-r--r--lem/postgres/queued.lua26
1 files changed, 20 insertions, 6 deletions
diff --git a/lem/postgres/queued.lua b/lem/postgres/queued.lua
index 2f597f4..f405dc0 100644
--- a/lem/postgres/queued.lua
+++ b/lem/postgres/queued.lua
@@ -1,6 +1,7 @@
--
-- This file is part of lem-postgres.
-- Copyright 2011 Emil Renner Berthing
+-- Copyright 2020 Asbjørn Sloth Tønnesen
--
-- lem-postgres is free software: you can redistribute it and/or
-- modify it under the terms of the GNU General Public License as
@@ -22,18 +23,32 @@ local postgres = require 'lem.postgres'
local remove = table.remove
local thisthread, suspend, resume = utils.thisthread, utils.suspend, utils.resume
+local Connection = postgres.Connection
+
local QConnection = {}
QConnection.__index = QConnection
+function QConnection:set_notifier(cb)
+ Connection.set_notifier(self.conn, cb)
+end
+
+local function cancel_all(t)
+ for i = 1, t.n - 1 do
+ resume(t[i])
+ t[i] = nil
+ end
+end
+
function QConnection:close()
local ok, err = self.conn:close()
- for i = 1, self.n - 1 do
- resume(self[i])
- self[i] = nil
- end
+ cancel_all(self)
return ok, err
end
-QConnection.__gc = QConnection.close
+
+function QConnection:__gc()
+ cancel_all(self)
+ self.conn = nil
+end
local function lock(self)
local n = self.n
@@ -64,7 +79,6 @@ local function wrap(method)
end
end
-local Connection = postgres.Connection
QConnection.exec = wrap(Connection.exec)
QConnection.prepare = wrap(Connection.prepare)
QConnection.run = wrap(Connection.run)