Async operation code tidy.

This commit is contained in:
n1474335 2017-02-27 17:29:43 +00:00
parent 11e06eeb75
commit 9f75077fe8
5 changed files with 21 additions and 48 deletions

View file

@ -97,9 +97,7 @@
<div id="input" class="split no-select"> <div id="input" class="split no-select">
<div class="title no-select"> <div class="title no-select">
Input Input
<div class="loading-icon" <div class="loading-icon" style="display: none"></div>
style="display: none">
</div>
<div class="btn-group io-btn-group"> <div class="btn-group io-btn-group">
<button type="button" class="btn btn-default btn-sm" id="clr-io"><img src="images/recycle-16x16.png" /> Clear I/O</button> <button type="button" class="btn btn-default btn-sm" id="clr-io"><img src="images/recycle-16x16.png" /> Clear I/O</button>
<button type="button" class="btn btn-default btn-sm" id="reset-layout"><img src="images/layout-16x16.png" /> Reset layout</button> <button type="button" class="btn btn-default btn-sm" id="reset-layout"><img src="images/layout-16x16.png" /> Reset layout</button>
@ -116,9 +114,7 @@
<div id="output" class="split"> <div id="output" class="split">
<div class="title no-select"> <div class="title no-select">
Output Output
<div class="loading-icon" <div class="loading-icon" style="display: none"></div>
style="display: none">
</div>
<div class="btn-group io-btn-group"> <div class="btn-group io-btn-group">
<button type="button" class="btn btn-default btn-sm" id="save-to-file" title="Save to file"><img src="images/save_as-16x16.png" /> Save to file</button> <button type="button" class="btn btn-default btn-sm" id="save-to-file" title="Save to file"><img src="images/save_as-16x16.png" /> Save to file</button>
<button type="button" class="btn btn-default btn-sm" id="switch" title="Move output to input"><img src="images/switch-16x16.png" /> Move output to input</button> <button type="button" class="btn btn-default btn-sm" id="switch" title="Move output to input"><img src="images/switch-16x16.png" /> Move output to input</button>

View file

@ -3135,7 +3135,7 @@ var OperationConfig = {
] ]
}, },
"Wait": { "Wait": {
description: "Waits for a number of milliseconds.", description: "Sleeps for a number of milliseconds.",
run: FlowControl.runWait, run: FlowControl.runWait,
inputType: "string", inputType: "string",
outputType: "string", outputType: "string",

View file

@ -79,7 +79,6 @@ Chef.prototype.bake = function(inputText, recipeConfig, options, progress, step)
chef.dish.get(Dish.HTML) : chef.dish.get(Dish.HTML) :
chef.dish.get(Dish.STRING); chef.dish.get(Dish.STRING);
ret.type = Dish.enumLookup(chef.dish.type); ret.type = Dish.enumLookup(chef.dish.type);
ret.duration = new Date().getTime() - startTime; ret.duration = new Date().getTime() - startTime;
ret.progress = progress; ret.progress = progress;
@ -90,7 +89,6 @@ Chef.prototype.bake = function(inputText, recipeConfig, options, progress, step)
chef.dish.get(Dish.HTML) : chef.dish.get(Dish.HTML) :
chef.dish.get(Dish.STRING); chef.dish.get(Dish.STRING);
ret.type = Dish.enumLookup(chef.dish.type); ret.type = Dish.enumLookup(chef.dish.type);
ret.duration = new Date().getTime() - startTime; ret.duration = new Date().getTime() - startTime;
ret.progress = err.progress; ret.progress = err.progress;
ret.error = err; ret.error = err;

View file

@ -225,8 +225,8 @@ var FlowControl = {
* @returns {Object} The updated state of the recipe. * @returns {Object} The updated state of the recipe.
*/ */
runWait: function(state) { runWait: function(state) {
var ings = state.opList[state.progress].getIngValues(), var ings = state.opList[state.progress].getIngValues(),
sleepTime = ings[0]; sleepTime = ings[0];
return new Promise(function(resolve, reject) { return new Promise(function(resolve, reject) {
setTimeout(function() { setTimeout(function() {

View file

@ -24,13 +24,11 @@ var HTMLApp = function(categories, operations, defaultFavourites, defaultOptions
this.chef = new Chef(); this.chef = new Chef();
this.manager = new Manager(this); this.manager = new Manager(this);
this.baking = false;
this.autoBake_ = false; this.autoBake_ = false;
this.progress = 0; this.progress = 0;
this.ingId = 0; this.ingId = 0;
this.baking = false;
this.rebake = false;
window.chef = this.chef; window.chef = this.chef;
}; };
@ -70,11 +68,12 @@ HTMLApp.prototype.handleError = function(err) {
* @param {bakingStatus} * @param {bakingStatus}
*/ */
HTMLApp.prototype.setBakingStatus = function(bakingStatus) { HTMLApp.prototype.setBakingStatus = function(bakingStatus) {
var inputLoadingIcon = document.querySelector("#input .title .loading-icon"); this.baking = bakingStatus;
var outputLoadingIcon = document.querySelector("#output .title .loading-icon");
var inputElement = document.querySelector("#input-text"); var inputLoadingIcon = document.querySelector("#input .title .loading-icon"),
var outputElement = document.querySelector("#output-text"); outputLoadingIcon = document.querySelector("#output .title .loading-icon"),
inputElement = document.querySelector("#input-text"),
outputElement = document.querySelector("#output-text");
if (bakingStatus) { if (bakingStatus) {
inputLoadingIcon.style.display = "inline-block"; inputLoadingIcon.style.display = "inline-block";
@ -97,49 +96,30 @@ HTMLApp.prototype.setBakingStatus = function(bakingStatus) {
/** /**
* Calls the Chef to bake the current input using the current recipe. * Calls the Chef to bake the current input using the current recipe.
* *
* @param {boolean} [step] - Set to true if we should only execute one operation instead of the * @param {boolean} [step] - Set to true if we should only execute one operation instead of the whole recipe.
* whole recipe.
*/ */
HTMLApp.prototype.bake = function(step) { HTMLApp.prototype.bake = function(step) {
var app = this; var app = this;
if (app.baking) { if (app.baking) return;
if (!app.rebake) {
// We do not want to keep autobaking
// Say that we will rebake and then try again later
app.rebake = true;
setTimeout(function() {
app.bake(step);
}, 500);
}
return;
}
app.rebake = false;
app.baking = true;
app.setBakingStatus(true); app.setBakingStatus(true);
try { try {
app.chef.bake( app.chef.bake(
app.getInput(), // The user's input app.getInput(), // The user's input
app.getRecipeConfig(), // The configuration of the recipe app.getRecipeConfig(), // The configuration of the recipe
app.options, // Options set by the user app.options, // Options set by the user
app.progress, // The current position in the recipe app.progress, // The current position in the recipe
step // Whether or not to take one step or execute the whole recipe step // Whether or not to take one step or execute the whole recipe
) )
.then(function(response) { .then(function(response) {
app.baking = false;
app.setBakingStatus(false); app.setBakingStatus(false);
if (!response) { if (!response) return;
return; if (response.error) app.handleError(response.error);
}
if (response.error) {
app.handleError(response.error);
}
app.options = response.options; app.options = response.options;
if (response.type === "html") { if (response.type === "html") {
app.dishStr = Utils.stripHtmlTags(response.result, true); app.dishStr = Utils.stripHtmlTags(response.result, true);
@ -159,10 +139,9 @@ HTMLApp.prototype.bake = function(step) {
} }
}) })
.catch(function(err) { .catch(function(err) {
console.error("Chef's promise was rejected, should never occur"); console.error("Chef's promise was rejected, this should never occur");
}); });
} catch (err) { } catch (err) {
app.baking = false;
app.setBakingStatus(false); app.setBakingStatus(false);
app.handleError(err); app.handleError(err);
} }