mirror of
https://codeberg.org/vlw/monkeydo.git
synced 2025-09-13 15:53:40 +02:00
Remove promise anipattern
This commit is contained in:
parent
46f3a07c85
commit
6b18c90228
2 changed files with 29 additions and 34 deletions
|
@ -75,19 +75,17 @@ class Monkey {
|
|||
|
||||
// Install a Monkeydo manifest
|
||||
async loadManifest(manifest) {
|
||||
return await new Promise((resolve,reject) => {
|
||||
if(typeof manifest !== "object") {
|
||||
try {
|
||||
manifest = JSON.parse(manifest);
|
||||
}
|
||||
catch {
|
||||
reject("Failed to load manifest");
|
||||
Promise.reject("Failed to load manifest");
|
||||
}
|
||||
}
|
||||
this.tasks.manifest = manifest.tasks;
|
||||
this.flags[0] = 1; // Manifest loaded: true
|
||||
resolve();
|
||||
});
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -48,14 +48,12 @@ export default class MonkeyMaster {
|
|||
this.comlink = await new Monkey();
|
||||
|
||||
// Wait for comlink to spin up
|
||||
return await new Promise((resolve,reject) => {
|
||||
if(!this.comlink) reject("Failed to establish Comlink with worker");
|
||||
if(!this.comlink) Promise.reject("Failed to establish Comlink with worker");
|
||||
|
||||
this.ready = true;
|
||||
// Send queued flags when worker is ready
|
||||
this.queue.sendAllFlags();
|
||||
resolve();
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
// Return a flag array index by name
|
||||
|
@ -104,7 +102,6 @@ export default class MonkeyMaster {
|
|||
// Load a Monkeydo manifest by URL or JSON string
|
||||
async loadManifest(manifest) {
|
||||
if(!this.ready) await this.init();
|
||||
return await new Promise((resolve,reject) => {
|
||||
let load = null;
|
||||
// Attempt load string as URL and fetch manifest
|
||||
try {
|
||||
|
@ -116,9 +113,9 @@ export default class MonkeyMaster {
|
|||
catch {
|
||||
load = this.comlink.loadManifest(manifest);
|
||||
}
|
||||
load.then(() => resolve())
|
||||
.catch(() => reject("Failed to load manifest"));
|
||||
});
|
||||
|
||||
load.then(() => Promise.resolve())
|
||||
.catch(() => Promise.reject("Failed to load manifest"));
|
||||
}
|
||||
|
||||
async stop() {
|
||||
|
|
Loading…
Add table
Reference in a new issue