diff --git a/Monkeydo.mjs b/Monkeydo.mjs index 7cd8033..62f8994 100644 --- a/Monkeydo.mjs +++ b/Monkeydo.mjs @@ -19,8 +19,7 @@ export default class Monkeydo extends MonkeyWorker { // Monkeydo manifest parsed with load() this.manifest = { - header: null, - body: null + tasks: null }; if(!window.Worker) { @@ -84,25 +83,17 @@ export default class Monkeydo extends MonkeyWorker { } // Make sure the parsed JSON is a valid Monkeydo manifest - if(!data.hasOwnProperty("header") || !data.hasOwnProperty("body")) { + if(!data.hasOwnProperty("tasks")) { this.debug(data); throw new Error(errorPrefix + "Expected 'header' and 'body' properties in object"); } - this.manifest.header = data.header; - this.manifest.body = data.body; + this.manifest.tasks = data.tasks; return true; } // Execute tasks from Monkeydo manifest - async do() { - const errorPrefix = "DO_FAILED: "; - // Abort if the manifest object doesn't contain any header data - if(!this.manifest.header) { - this.debug(this.manifest.header); - throw new Error(errorPrefix + `Expected header object from contructed property`); - } - + do() { // Hand over the loaded manifest to the MonkeyWorker task manager const monkey = this.giveManifest(); this.play(); diff --git a/do/Monkey.js b/do/Monkey.js index 7513e4c..81cde6b 100644 --- a/do/Monkey.js +++ b/do/Monkey.js @@ -3,8 +3,8 @@ class Monkey { constructor(manifest) { const self = this; - this.data = manifest.body; - this.dataLength = this.data.length - 1; + this.tasks = manifest.tasks; + this.tasksLength = this.tasks.length - 1; this.flags = { playing: 0, @@ -62,7 +62,7 @@ class Monkey { // Schedule task for execution by index queueNext() { this.flags.playing = 1; - const data = this.data[this.i]; + const data = this.tasks[this.i]; const task = { wait: data[0], func: data[1], @@ -73,7 +73,7 @@ class Monkey { this.queue.task = setTimeout(() => this.run(task),task.wait); // We're out of tasks to schedule.. - if(this.i >= this.dataLength) { + if(this.i >= this.tasksLength) { this.i = -1; // Exit if we're out of loops if(this.flags.loop === 0) {