+ * Schedules a task within the current layer just as scheduleTast() does,
+ * except that another specified layer will be blocked until this task
+ * completes, and this task will not start until the other layer is
+ * ready.
+ *
+ * Essentially, a task is scheduled in both layers, and the specified task
+ * will only be performed once both layers are ready, and neither layer may
+ * proceed until this task completes.
+ *
+ * Note that there is no way to specify whether the task starts blocked,
+ * as whether the task is blocked depends completely on whether the
+ * other layer is currently ready.
+ *
+ * @param {Guacamole.Layer} otherLayer The other layer which must be blocked
+ * until this task completes.
+ * @param {function} handler The function to call when possible.
+ */
+ function scheduleTaskSynced(otherLayer, handler) {
+
+ // If we ARE the other layer, no need to sync.
+ // Syncing would result in deadlock.
+ if (layer === otherLayer)
+ scheduleTask(handler);
+
+ // Otherwise synchronize operation with other layer
+ else {
+
+ var drawComplete = false;
+ var layerLock = null;
+
+ function performTask() {
+
+ // Perform task
+ handler();
+
+ // Unblock the other layer now that draw is complete
+ if (layerLock != null)
+ layerLock.unblock();
+
+ // Flag operation as done
+ drawComplete = true;
+
+ }
+
+ // Currently blocked draw task
+ var task = scheduleTask(performTask, true);
+
+ // Unblock draw task once source layer is ready
+ otherLayer.sync(task.unblock);
+
+ // Block other layer until draw completes
+ // Note that the draw MAY have already been performed at this point,
+ // in which case creating a lock on the other layer will lead to
+ // deadlock (the draw task has already run and will thus never
+ // clear the lock)
+ if (!drawComplete)
+ layerLock = otherLayer.sync(null, true);
+
+ }
+ }
+
+ /**