scheduled-function-scheduler-running-pScheduled and Periodic Functionsunschedule-functionspawn-periodic-functionGoTo Top

spawn-periodic-function   function repeat-interval &key count name verbose => thread[Function]

Purpose
Spawn a thread invoking function every repeat-interval seconds.

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 function, if function is a symbol, otherwise nil)
verbose     A generalized boolean (default is *periodic-function-verbose*)
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, function will continue to be invoked every repeat-interval seconds until the periodic-function thread is killed or until function calls kill-periodic-function. Otherwise, count is decremented by one prior to each invocation of function and, if it is negative, the periodic function is terminated.

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, continuing as long as the control shell is running:
  > (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


scheduled-function-scheduler-running-pScheduled and Periodic Functionsunschedule-functionspawn-periodic-functionGoTo Top