Change wait to use a promise instead of being called every frame

This commit is contained in:
DD Liu 2017-06-05 16:55:15 -04:00
parent ecf535f4c3
commit ab0cef52eb

View file

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