diff --git a/src/frontend/devices.ts b/src/frontend/devices.ts new file mode 100644 index 0000000..25d6553 --- /dev/null +++ b/src/frontend/devices.ts @@ -0,0 +1,28 @@ +import chalk from "chalk" + +export async function forEachDevice( + devices: Device[], + parallel: boolean, + callback: (device: Device) => Promise, + deviceKey: (device: Device) => string = d => d as any as string, +) { + let jobs = [] + let isMultiDevice = devices.length > 1 + for (let device of devices) { + if (isMultiDevice) { + console.log(` + +${chalk.bold(chalk.blueBright(deviceKey(device)))} +`) + } + + let job = callback(device) + if (parallel) { + jobs.push(job) + } else { + await job + } + } + + await Promise.all(jobs) +}