-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfinalizable.el
34 lines (24 loc) · 1019 Bytes
/
finalizable.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
;;; finalizable.el --- finalize generic function for EIEIO -*- lexical-binding: t; -*-
;; This is free and unencumbered software released into the public domain.
;;; Summary:
;; This extends finalizers to EIEIO with a `finalize' generic function
;; and a `finalizable' mixin class.
;;; Code:
(require 'cl-generic)
(require 'eieio)
(require 'finalize)
(defclass finalizable ()
()
(:documentation
"Classes that inherit from this mixin must implement the
`finalize' method, which will receive a copy of the original
object. The copy is made after `initialize-instance'.")
:abstract t)
(cl-defmethod initialize-instance :after ((object finalizable) &key)
(finalize-register object #'finalize (copy-sequence object)))
(cl-defgeneric finalize (object-copy)
"Finalize OBJECT-COPY after it has been garbage collected.
OBJECT-COPY is a copy made just after `initialize-instance' using
`copy-sequence'. The object itself is unavailable to this method.")
(provide 'finalizable)
;;; finalizable.el ends here