mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-24 23:12:24 -05:00
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
This commit is contained in:
parent
19e6a1d4c9
commit
7b917cabb4
1 changed files with 6 additions and 1 deletions
|
@ -949,8 +949,9 @@ class Boost {
|
||||||
if (motor) {
|
if (motor) {
|
||||||
motor._status = feedback;
|
motor._status = feedback;
|
||||||
// Makes sure that commands resolve both when they actually complete and when they fail
|
// 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);
|
const commandCompleted = feedback & (BoostPortFeedback.COMPLETED ^ BoostPortFeedback.DISCARDED);
|
||||||
if (commandCompleted && motor.pendingPromiseFunction) {
|
if (!isBusy && commandCompleted && motor.pendingPromiseFunction) {
|
||||||
motor.pendingPromiseFunction();
|
motor.pendingPromiseFunction();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1646,6 +1647,10 @@ class Scratch3BoostBlocks {
|
||||||
const promises = motors.map(portID => {
|
const promises = motors.map(portID => {
|
||||||
const motor = this._peripheral.motor(portID);
|
const motor = this._peripheral.motor(portID);
|
||||||
if (motor) {
|
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 => {
|
return new Promise(resolve => {
|
||||||
motor.turnOnForDegrees(degrees, sign);
|
motor.turnOnForDegrees(degrees, sign);
|
||||||
motor.pendingPromiseFunction = resolve;
|
motor.pendingPromiseFunction = resolve;
|
||||||
|
|
Loading…
Reference in a new issue