From 7b917cabb47e804a7c6777a526048c13da4614f1 Mon Sep 17 00:00:00 2001 From: Kevin Andersen Date: Tue, 9 Apr 2019 09:30:26 -0400 Subject: [PATCH] Added isBusy-flag in onMessage to make sure promises aren't resolved if the motor is still busy. Added check in motorOnForRotation() that ensure that any previous pendingPromiseFunction() is resolved before creating a new one, to avoid hanging blocks --- src/extensions/scratch3_boost/index.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/extensions/scratch3_boost/index.js b/src/extensions/scratch3_boost/index.js index fe841244f..5076386e4 100644 --- a/src/extensions/scratch3_boost/index.js +++ b/src/extensions/scratch3_boost/index.js @@ -949,8 +949,9 @@ class Boost { if (motor) { motor._status = feedback; // Makes sure that commands resolve both when they actually complete and when they fail + const isBusy = feedback & BoostPortFeedback.IN_PROGRESS; const commandCompleted = feedback & (BoostPortFeedback.COMPLETED ^ BoostPortFeedback.DISCARDED); - if (commandCompleted && motor.pendingPromiseFunction) { + if (!isBusy && commandCompleted && motor.pendingPromiseFunction) { motor.pendingPromiseFunction(); } } @@ -1646,6 +1647,10 @@ class Scratch3BoostBlocks { const promises = motors.map(portID => { const motor = this._peripheral.motor(portID); if (motor) { + if (motor.pendingPromiseFunction) { + // If there's already a promise for this motor it must be resolved to avoid hanging blocks. + motor.pendingPromiseFunction(); + } return new Promise(resolve => { motor.turnOnForDegrees(degrees, sign); motor.pendingPromiseFunction = resolve;