From ab0cef52eb759bad7e7aad3d637fa31a19b1c18c Mon Sep 17 00:00:00 2001 From: DD Liu Date: Mon, 5 Jun 2017 16:55:15 -0400 Subject: [PATCH 1/2] Change wait to use a promise instead of being called every frame --- src/blocks/scratch3_control.js | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/blocks/scratch3_control.js b/src/blocks/scratch3_control.js index f3b53baa2..f460399e1 100644 --- a/src/blocks/scratch3_control.js +++ b/src/blocks/scratch3_control.js @@ -73,18 +73,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 { - const duration = Math.max(0, 1000 * Cast.toNumber(args.DURATION)); - if (util.stackFrame.timer.timeElapsed() < duration) { - util.yield(); - } - } + wait (args) { + const duration = Math.max(0, 1000 * Cast.toNumber(args.DURATION)); + return new Promise(resolve => { + setTimeout(() => { + resolve(); + }, duration); + }); } if (args, util) { From e237d2484611298d2c8faf494f20b1ec431ea270 Mon Sep 17 00:00:00 2001 From: DD Liu Date: Tue, 6 Jun 2017 10:21:27 -0400 Subject: [PATCH 2/2] fix lint --- src/blocks/scratch3_control.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/blocks/scratch3_control.js b/src/blocks/scratch3_control.js index f460399e1..975dfeb81 100644 --- a/src/blocks/scratch3_control.js +++ b/src/blocks/scratch3_control.js @@ -1,5 +1,4 @@ const Cast = require('../util/cast'); -const Timer = require('../util/timer'); class Scratch3ControlBlocks { constructor (runtime) {