Script TheSkyX  Version 1.27
Synchronous vs. Asynchronous Execution

A number of the objects in this library have a property to control if the operation is synchronous or asynchronous.

See sky6RASCOMTele::Asynchronous and ccdsoftCamera::lAsynchronous.

The difference between synchronous and asynchronous execution may seem a bit confusing at first and this section attempts to explain the two modes of operation. Program execution in most high-level languages is usually very straightforward. Your program starts at the first line of source code and each line of code executed sequentially thereafter. Easy enough.

Synchronous program execution is somewhat similar to the above. Your program is executed line by line, one line at a time. Each time a function is called, program execution waits until that function returns before continuing to the next line of code.

This method of execution can have undesirable ramifications. Suppose a function is called to start a time consuming process. What if you want to stop the lengthy process? With synchronous execution, your program is stuck, or blocked, waiting for the process to end, with no way out.

Asynchronous execution avoids the blocking call. You are essentially saying, I know this function call is going to take a great deal of time, but my program doesn't want to wait while it executes.

    TakePicture(long lExposureTimeInSeconds)
                    stuff to take a picture...
            While (Not CancelledByUser)

            if (CancelledByUser == true)
                    return cancelError
                    return noError

            Print("TakePicture() function returns!")

In the above pseudo-code the TakePicture() methood operates using synchronous execution, you'll have to wait two minutes for the call to DoAPicture() to return and display the "TakePicture() function returns!" message. There is no way to cancel the picture.

Using asynchronous execution, the TakePicture() function will initiate the operation and return immediately and show the message (this implementation is not shown in the above code). Although the two-minute process is not complete, your program can continue to execute. In this manner, your program could set the CancelledByUser variable to true to cancel the picture. It could also poll or ask the TakePicture() function when the exposure is completed, or if an error occurred during the process.

See also
sky6RASCOMTele::IsSlewComplete (will throw an exception upon error)
ccdsoftCamera::IsExposureComplete (will throw an exception upon error)
ScriptTheSkyX Examples
(C) Software Bisque, Inc. All rights reserved.