From 1dfb9dfa67a240b80a5a13b9b1293c790b20cd60 Mon Sep 17 00:00:00 2001 From: jmoenig Date: Tue, 3 Jul 2018 09:32:37 +0200 Subject: [PATCH] speed up HTTP based hardware APIs by not waiting for the result if the URL reporter is used inside a REPORT block within a custom COMMAND block definition --- gui.js | 4 ++-- history.txt | 8 +++++++- snap.html | 6 +++--- threads.js | 14 +++++++++++--- 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/gui.js b/gui.js index b635fce1..f41c6c50 100644 --- a/gui.js +++ b/gui.js @@ -75,7 +75,7 @@ isRetinaSupported, SliderMorph, Animation, BoxMorph, MediaRecorder*/ // Global stuff //////////////////////////////////////////////////////// -modules.gui = '2018-June-21'; +modules.gui = '2018-July-03'; // Declarations @@ -3504,7 +3504,7 @@ IDE_Morph.prototype.aboutSnap = function () { module, btn1, btn2, btn3, btn4, licenseBtn, translatorsBtn, world = this.world(); - aboutTxt = 'Snap! 4.2\nBuild Your Own Blocks\n\n' + aboutTxt = 'Snap! 4.2.1 - dev -\nBuild Your Own Blocks\n\n' + 'Copyright \u24B8 2018 Jens M\u00F6nig and ' + 'Brian Harvey\n' + 'jens@moenig.org, bh@cs.berkeley.edu\n\n' diff --git a/history.txt b/history.txt index 4e113021..4d6cf2f5 100755 --- a/history.txt +++ b/history.txt @@ -4179,7 +4179,6 @@ Translation Updates: ------ * Threads, Objects: made "When I am stopped" scripts atomic, so you can use loops - === v4.2 major release === v4.2 New Features: @@ -4211,3 +4210,10 @@ Translation Updates: * German, thanks, Jadga! * Portuguese, thanks, Manuel! * Catalan, thanks, Joan! + +=== in development === + +180703 +------ +* speed up HTTP based hardware APIs (by not waiting for the result if the URL reporter is used inside a REPORT block within a custom COMMAND block definition) + diff --git a/snap.html b/snap.html index c270fa89..8d9ee3fe 100755 --- a/snap.html +++ b/snap.html @@ -2,14 +2,14 @@ - Snap! Build Your Own Blocks 4.2 + Snap! Build Your Own Blocks 4.2.1 - dev - - + - + diff --git a/threads.js b/threads.js index 361ecd06..f237186c 100644 --- a/threads.js +++ b/threads.js @@ -62,7 +62,7 @@ StageMorph, SpriteMorph, StagePrompterMorph, Note, modules, isString, copy, isNil, WatcherMorph, List, ListWatcherMorph, alert, console, TableMorph, TableFrameMorph, ColorSlotMorph, isSnapObject*/ -modules.threads = '2018-June-21'; +modules.threads = '2018-July-03'; var ThreadManager; var Process; @@ -789,7 +789,7 @@ Process.prototype.doReport = function (block) { if (this.isClicked && (block.topBlock() === this.topBlock)) { this.isShowingResult = true; } - if (this.context.expression.partOfCustomCommand) { + if (block.partOfCustomCommand) { this.doStopCustomBlock(); this.popContext(); } else { @@ -812,8 +812,9 @@ Process.prototype.doReport = function (block) { } // in any case evaluate (and ignore) // the input, because it could be - // and HTTP Request for a hardware extension + // an HTTP Request for a hardware extension this.pushContext(block.inputs()[0], outer); + this.context.isCustomCommand = block.partOfCustomCommand; }; // Process: Non-Block evaluation @@ -2301,6 +2302,11 @@ Process.prototype.reportURL = function (url) { this.httpRequest = new XMLHttpRequest(); this.httpRequest.open("GET", url, true); this.httpRequest.send(null); + if (this.context.isCustomCommand) { + // special case when ignoring the result, e.g. when + // communicating with a robot to control its motors + return null; + } } else if (this.httpRequest.readyState === 4) { response = this.httpRequest.responseText; this.httpRequest = null; @@ -4004,6 +4010,7 @@ Process.prototype.reportAtomicSort = function (list, reporter) { activeNote audio oscillator for interpolated ops, don't persist activeSends forked processes waiting to be completed isCustomBlock marker for return ops + isCustomCommand marker for interpolated blocking reporters (reportURL) emptySlots caches the number of empty slots for reification tag string or number to optionally identify the Context, as a "return" target (for the "stop block" primitive) @@ -4034,6 +4041,7 @@ function Context( this.activeAudio = null; this.activeNote = null; this.isCustomBlock = false; // marks the end of a custom block's stack + this.isCustomCommand = null; // used for ignoring URL reporters' results this.emptySlots = 0; // used for block reification this.tag = null; // lexical catch-tag for custom blocks this.isFlashing = false; // for single-stepping