[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/emacsql 5962268f83 184/427: Split off reaper code.
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/emacsql 5962268f83 184/427: Split off reaper code. |
Date: |
Tue, 13 Dec 2022 02:59:40 -0500 (EST) |
branch: elpa/emacsql
commit 5962268f83b0221e5a3b994e3a5abbf126685272
Author: Christopher Wellons <wellons@nullprogram.com>
Commit: Christopher Wellons <wellons@nullprogram.com>
Split off reaper code.
---
Makefile | 4 ++--
emacsql.el | 44 ++------------------------------------------
2 files changed, 4 insertions(+), 44 deletions(-)
diff --git a/Makefile b/Makefile
index 175cf583c3..dc9bb14523 100644
--- a/Makefile
+++ b/Makefile
@@ -5,8 +5,8 @@ BATCH := $(EMACS) -batch -Q -L .
COMPILE := $(BATCH) -f batch-byte-compile
TEST := $(BATCH) -l $(PACKAGE)-tests.elc -f ert-run-tests-batch
-EL = emacsql-compiler.el emacsql.el emacsql-sqlite.el emacsql-psql.el \
- emacsql-tests.el
+EL = emacsql-reap.el emacsql-compiler.el emacsql.el emacsql-sqlite.el \
+ emacsql-psql.el emacsql-tests.el
ELC = $(EL:.el=.elc)
diff --git a/emacsql.el b/emacsql.el
index ad279ee013..47687f6e3c 100644
--- a/emacsql.el
+++ b/emacsql.el
@@ -59,6 +59,7 @@
(require 'cl-lib)
(require 'eieio)
+(require 'emacsql-reap)
(require 'emacsql-compiler)
(defclass emacsql-connection ()
@@ -194,50 +195,9 @@ specific error conditions."
;; Automatic connection cleanup:
-(defvar emacsql-connections ()
- "Collection of all known emacsql connections.
-This collection exists for cleanup purposes.")
-
-(defvar emacsql-reap-timer nil
- "Timer used to check for dead emacsql connections.")
-
(defun emacsql-register (connection)
"Add CONNECTION to the global connection list."
- (emacsql-start-reap-timer)
- (push (cons (copy-sequence connection) (emacsql--ref connection))
- emacsql-connections))
-
-(defun emacsql--ref (thing)
- "Create a weak reference to THING."
- (let ((ref (make-hash-table :test 'eq :size 1 :weakness 'value)))
- (prog1 ref
- (setf (gethash t ref) thing))))
-
-(defun emacsql--deref (ref)
- "Retrieve value from REF."
- (gethash t ref))
-
-(defun emacsql-reap ()
- "Clean up after lost connections."
- (cl-loop for (conn-copy . ref) in emacsql-connections
- when (null (emacsql--deref ref))
- count (prog1 t (ignore-errors (emacsql-close conn-copy)))
- into total
- else collect (cons conn-copy ref) into connections
- finally (progn
- (setf emacsql-connections connections)
- (cl-return total))))
-
-(cl-defun emacsql-start-reap-timer (&optional (interval 60))
- "Start the automatic `emacql-reap' timer."
- (unless emacsql-reap-timer
- (setf emacsql-reap-timer (run-at-time interval interval #'emacsql-reap))))
-
-(defun emacsql-stop-reap-timer ()
- "Stop the automatic `emacsql-reap' timer."
- (when (timerp emacsql-reap-timer)
- (cancel-timer emacsql-reap-timer)
- (setf emacsql-reap-timer nil)))
+ (emacsql-reap-register connection #'emacsql-close (copy-sequence
connection)))
;; Useful macros:
- [nongnu] elpa/emacsql 64c3a03d62 169/427: Flesh out some more README., (continued)
- [nongnu] elpa/emacsql 64c3a03d62 169/427: Flesh out some more README., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 9f6c10eca0 172/427: Move error checking out to helper mix-in., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 4f76b94f7c 168/427: Set psql to print nil for NULL., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 7434263d82 174/427: Oops, drop leftover function call., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql ca62adc4b2 177/427: Add debug argument to emacsql-psql., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql afef528d81 179/427: Fix memoization to include type map., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql b2f2dd37cf 178/427: Allow connection to specify their own types., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 4aa889882d 182/427: Fix slot allocation on emacsql-connection., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 769abe20fa 183/427: Don't rely on a closure in cleanup hook., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql e9efb0803e 185/427: Oops, include the reap source., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 5962268f83 184/427: Split off reaper code.,
ELPA Syncer <=
- [nongnu] elpa/emacsql f8c3d9fce2 369/427: Silence Emacs 25's byte-compiler, ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 8e34660ba1 370/427: Allow `gcc` as a separate option for C compilation., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 739c24cab6 389/427: Add kludge to work around `cl-defmethod' bug, ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 18b40213fd 403/427: No longer use obsolete generalized variable `point', ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 6d999ba39d 400/427: Update library headers, ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql a29b9e7ea5 388/427: No longer needlessly require url and url-http, ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 20e390ea06 401/427: Add FAQ to README.md, ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 30912aa69e 404/427: Include ../.config.mk in sqlite/Makefile, ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql f5da68e5f9 391/427: Fix quoting in docstring, ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql a4d01edd71 411/427: Adjust emacsql-pg to new pg version from original author, ELPA Syncer, 2022/12/13