How to prevent subsequent javascript statements from executing before animation/timeline complete?

Could someone provide a bit of guidance? I am trying to prevent subsequent execution of code until the animation/timeline has completed (or in this case, arrived at a pause timeline action marker). The playPropertyInstructions function contains the code to run the timeline. This works when invoked through the .when method. However, the .when method is supposed to wait until the animation is complete. Ideally, the alert would specify the time at which the pause timeline marker has been specified. The .when method does not wait. Can someone tell me what I’m doing incorrectly or is there a different way to prevent further execution of code until a timeline animation has completed?

$("#LengthSwitch").click(function() {
        $("#LengthSwitch").html("<img src = '${resourcesFolderName}/LengthOn.svg'>");
		$.when(playPropertyInstructions("#LengthSwitch", "length", 21)).done(function() {
			alert("Timeline marker is at " + hypeDocument.currentTimeInTimelineNamed('Calibration Instructions'));
       });	 	
  });