From 3437a0a730d8329a37a5a6b6b241982c7dbff743 Mon Sep 17 00:00:00 2001 From: theit8514 Date: Sun, 12 Dec 2021 19:50:41 -0500 Subject: [PATCH] Await scp multiple script copy --- src/NetscriptFunctions.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/NetscriptFunctions.ts b/src/NetscriptFunctions.ts index 5b737bfca..8f017239c 100644 --- a/src/NetscriptFunctions.ts +++ b/src/NetscriptFunctions.ts @@ -1056,12 +1056,16 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS { } if (scriptname && scriptname.constructor === Array) { // Recursively call scp on all elements of array - let res = false; - await scriptname.forEach(async function (script) { - if (await NetscriptFunctions(workerScript).scp(script, hostname1, hostname2)) { - res = true; + const scripts: Array = scriptname; + if (scripts.length === 0) { + throw makeRuntimeErrorMsg("scp", "No scripts to copy"); + } + 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); }