Merge pull request #593 from fsih/fixWaitCalledEveryFrame

Change wait to use a promise instead of being called every frame
This commit is contained in:
DD Liu 2017-06-08 15:35:48 -04:00 committed by GitHub
commit fb986effe6

View file

@ -1,5 +1,4 @@
const Cast = require('../util/cast');
const Timer = require('../util/timer');
class Scratch3ControlBlocks {
constructor (runtime) {
@ -73,18 +72,13 @@ class Scratch3ControlBlocks {
util.startBranch(1, true);
}
wait (args, util) {
if (!util.stackFrame.timer) {
util.stackFrame.timer = new Timer();
util.stackFrame.timer.start();
util.yield();
this.runtime.requestRedraw();
} else {
wait (args) {
const duration = Math.max(0, 1000 * Cast.toNumber(args.DURATION));
if (util.stackFrame.timer.timeElapsed() < duration) {
util.yield();
}
}
return new Promise(resolve => {
setTimeout(() => {
resolve();
}, duration);
});
}
if (args, util) {