Search code examples
lispautolisp

AutoLisp - Run two functions at once


I have this whirl function that I want to run along side with my main code. How do I call Whirl without waiting for it to return a reply?

    ;; Global variable
    (setq *bWhirl* nil)

    ;; Test function
    (defun C:fcnTest01()
        
        ;; Run without waiting for return
        (Whirl "Working..." "Done")
        
        ;; Code
        (princ "\nRuns program.\n")
        (command "DELAY" "5000")
        
        ;; Finalizing
        (setq *bWhirl* nil)
        (terpri)(princ)
    );defun C:fcnTest01

    ;; Whirl function
    (defun Whirl (sFrontText sEndText / rWhirl)

        ;; Validation
        (if (/= (type sFrontText) 'STR)(progn
            (princ "\nThe input variable is not a string variable.")
            (exit)
        ));if<-progn
    
        ;; Initializing
        (setq rCmdEcho (getvar "CMDECHO"))(setvar "CMDECHO" 0)
        (setq *bWhirl* T)
        (terpri); Prevents clearing any previously entered strings
    
        ;; Looping until changed
        (while *bWhirl*
            (if rWhirl
                (setq rWhirl (1+ rWhirl))
                (setq rWhirl 1)
            );if
            (if (> rWhirl 4)(setq rWhirl 1))
            (princ (strcat "\r" sFrontText (cond
                ((= rWhirl 1)"-")
                ((= rWhirl 2) "\\")
                ((= rWhirl 3) "|")
                ((= rWhirl 4) "/")
            )));princ <- strcat <- cond
            (command "DELAY" "500")
        );while
    
        ;; Finalizing
        (if (= (type sEndText) 'STR)
            (princ (strcat "\r" sFrontText sEndText))
            (princ (strcat "\r" sFrontText))
        );if
        (setvar "CMDECHO" rCmdEcho)
        (princ)
    );defun Whirl

This `Whirl` function was modified from [ExcelDraw.lsp][1].

  [1]: https://github.com/yyxuxyy/autolisp/blob/master/DrawExcel.lsp

Solution

  • AutoLISP does not support multiple threads - programs are executed in 'series' using a single processor thread. As such, this is unfortunately not possible.