Use promises to yield

This commit is contained in:
Eric Rosenbaum 2018-05-31 17:09:47 -04:00
parent 46f885fc03
commit 2348d55f14

View file

@ -204,11 +204,11 @@ class Scratch3SoundBlocks {
} }
setEffect (args, util) { setEffect (args, util) {
this._updateEffect(args, util, false); return this._updateEffect(args, util, false);
} }
changeEffect (args, util) { changeEffect (args, util) {
this._updateEffect(args, util, true); return this._updateEffect(args, util, true);
} }
_updateEffect (args, util, change) { _updateEffect (args, util, change) {
@ -229,7 +229,11 @@ class Scratch3SoundBlocks {
if (util.target.audioPlayer === null) return; if (util.target.audioPlayer === null) return;
util.target.audioPlayer.setEffect(effect, soundState.effects[effect]); util.target.audioPlayer.setEffect(effect, soundState.effects[effect]);
this.runtime.requestRedraw();
// Yield until the next tick.
return new Promise(resolve => {
resolve();
});
} }
_syncEffectsForTarget (target) { _syncEffectsForTarget (target) {
@ -265,12 +269,12 @@ class Scratch3SoundBlocks {
setVolume (args, util) { setVolume (args, util) {
const volume = Cast.toNumber(args.VOLUME); const volume = Cast.toNumber(args.VOLUME);
this._updateVolume(volume, util); return this._updateVolume(volume, util);
} }
changeVolume (args, util) { changeVolume (args, util) {
const volume = Cast.toNumber(args.VOLUME) + util.target.volume; const volume = Cast.toNumber(args.VOLUME) + util.target.volume;
this._updateVolume(volume, util); return this._updateVolume(volume, util);
} }
_updateVolume (volume, util) { _updateVolume (volume, util) {
@ -278,7 +282,11 @@ class Scratch3SoundBlocks {
util.target.volume = volume; util.target.volume = volume;
if (util.target.audioPlayer === null) return; if (util.target.audioPlayer === null) return;
util.target.audioPlayer.setVolume(util.target.volume); util.target.audioPlayer.setVolume(util.target.volume);
this.runtime.requestRedraw();
// Yield until the next tick.
return new Promise(resolve => {
resolve();
});
} }
getVolume (args, util) { getVolume (args, util) {