[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Peridic tasks in MCL 2.0.1
- To: info-mcl@digitool.com
- Subject: Peridic tasks in MCL 2.0.1
- From: poeck@informatik.uni-wuerzburg.de (Karsten Poeck)
- Date: 12 Jan 1995 09:30:12 GMT
- Organization: University of Wuerzburg
- Sender: owner-info-mcl@digitool.com
For some applications we need to execute a task peridically in background.
e.g. listening for an incomming tcp-connection.
Up to now we used an undocumented mcl internal
(CCL::%INSTALL-PERIODIC-TASK), but that might not be the best idea.
Using the documented ccl:*eventhook* I can get a similar functionality,
code is included in the appendix, but I wonder if there is a better, safer
or cleaner way to do this
Karsten
;;;;sample code
(in-package :cl-user)
(defvar *id-tasks-plist* nil)
(defun install-simple-peridic-task (id funktion interval &key (ignore-errors t))
(declare (ignore interval))
;will handle interval in the future
(let ((old-function (getf *id-tasks-plist* id))
(new-function #'(lambda()
(when (zerop (mod (get-internal-run-time) 60))
(if ignore-errors
(ignore-errors (funcall funktion))
(funcall funktion)
)))))
(when old-function
(setq ccl:*eventhook* (delete old-function ccl:*eventhook*)))
(pushnew new-function ccl:*eventhook*)
(setf (getf *id-tasks-plist* id)
new-function)
)
)
(defun deinstall-simple-periodic-task (id)
(setq ccl:*eventhook* (delete (getf *id-tasks-plist* id) ccl:*eventhook*)))
#|
(install-simple-peridic-task
:test
#'(lambda()
(multiple-value-bind
(sekunde minute stunde tag monat jahr wochentag egal1 egal2)
(get-decoded-Time)
(declare (ignore stunde tag monat jahr wochentag egal1 egal2))
(format ccl:*top-listener* "~2d:~2d" minute sekunde))
(let ((a 'a))
(+ 1 a))
)
100)
(deinstall-simple-periodic-task :test)
|#
Karsten A. Poeck, Lehrstuhl fuer Informatik VI, Universitaet Wuerzburg
Allesgrundweg 12, 97218 Gerbrunn, Germany
E-mail: poeck@informatik.uni-wuerzburg.de
Tel ++ 49 931 70561 18, Fax ++ 49 931 70561 20
http://wi6a76.informatik.uni-wuerzburg.de/HTMLs/ls6-info/Assis/poeck/poeck.html