Synchronization
Usually, Canvas
operations execute as soon as possible. For instance, consider the following example:
The first circle appears on the canvas immediately, while the second one shows up after a 1 second delay due to the sleep
call.
More realistically, you may have a series of drawing operations that you want to present simultaneously rather than progressively. For such scenarios, you can use a Canvas.sync
block that ensures all nested drawing operations are presented only when the block exits. Behind the scenes, Scripton automatically routes rendering calls to an offscreen buffer and defers its presentation.
For the example above, the synchronized version would be as follows:
Both circles will now be shown simultaneously after a 1 second delay when the with
block exits.