Merge pull request #1869 from theit8514/scp-async

Await scp multiple script copy
This commit is contained in:
hydroflame 2021-12-13 12:08:25 -05:00 committed by GitHub
commit e9623340af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1056,12 +1056,16 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
} }
if (scriptname && scriptname.constructor === Array) { if (scriptname && scriptname.constructor === Array) {
// Recursively call scp on all elements of array // Recursively call scp on all elements of array
let res = false; const scripts: Array<string> = scriptname;
await scriptname.forEach(async function (script) { if (scripts.length === 0) {
if (await NetscriptFunctions(workerScript).scp(script, hostname1, hostname2)) { throw makeRuntimeErrorMsg("scp", "No scripts to copy");
res = true;
} }
}); let res = true;
await Promise.all(scripts.map(async function(script) {
if (!await NetscriptFunctions(workerScript).scp(script, hostname1, hostname2)) {
res = false;
}
}));
return Promise.resolve(res); return Promise.resolve(res);
} }