Share

About Asynchronous JavaScript APIs

AutoCAD JavaScript asynchronous Application Programming Interface (APIs) follow a promise pattern, which does not block and wait for the long-running computation to complete, instead the pattern returns an object which represents the promised result.

A promise implements a method for registering callbacks for state change notifications, commonly named the then method. The then() method takes 2 callbacks: success() and error() as shown in the sample code.

Acad.Application.activedocument.capturePreview(200,200).then(success,error);

The success callback function is invoked when the promise enters the completed state, passing in the result from the computation. The error is invoked when the promise goes into the failed state.

The benefits of asynchronous APIs can be summarized as:

  • Guarantee of synchronous communication, with the added ability to handle failures and exceptions
  • Does not block a thread's operations until the call completes

These benefits allow you to better harness the parallelism in your system.

Was this information helpful?