![]() | ![]() | ![]() | spawn-periodic-function | ![]() |
|
| function repeat-interval
&key count name verbose
=> thread | [Function] |
Purpose
Spawn a thread invoking
Package :portable-threads
Module :portable-threads
Arguments and values
| function | A function designator specifying a function object of no arguments | |
| repeat-interval | A number (representing seconds) | |
| count | A number or nil (default is nil)
| |
| name | An object (typically a string or a symbol; default is
nil)
| |
| verbose | A generalized boolean
(default is | |
| thread | A thread |
Returns
The object representing the thread associated with the
periodic function.
Errors
Threads (multiprocessing) is not supported on the
Common Lisp implementation.
Description
If count is nil,
See also
*periodic-function-verbose*
all-threads
kill-periodic-function
kill-thread
make-scheduled-function
schedule-function
schedule-function-relative
Examples
Spawn a simple periodic function that is invoked every 0.1 seconds,
but that only runs twice:
> (spawn-periodic-function #'(lambda () (print "Hello!")) 0.1
:name 'hello
:count 2)
#<thread Periodic Function hello>
>
"Hello!"
"Hello!"
Spawn a simple periodic function that is invoked every 0.1 seconds
that runs up to 20 times, but with a 10% chance on each invocation of
terminating early:
> (spawn-periodic-function
#'(lambda ()
(when (zerop (random 10))
(kill-periodic-function))
(print "Hello!"))
0.1
:count 20
:verbose 't)
;; Spawning periodic-function thread for...
#<thread Periodic Function>
>
"Hello!"
"Hello!"
"Hello!"
"Hello!"
;; Killing periodic-function...
;; Exiting periodic-function thread
Define and spawn a periodic function that is invoked every 0.5 seconds
to signal a half-second-interrupt-event
> (define-event-class half-second-timer-event (timer-interrupt-event)
())
half-second-timer-event
> (defun half-second-timer ()
(unless (control-shell-running-p)
(kill-periodic-function))
(signal-event 'half-second-timer-event))
half-second-timer
> (spawn-periodic-function 'half-second-timer 0.5)
#<thread Periodic Function half-second-timer>
>
The GBBopen Project
![]() | ![]() | ![]() | spawn-periodic-function | ![]() |