20 lines
782 B
TypeScript
20 lines
782 B
TypeScript
/** Legacy APIs cannot represent partial data in their successful array envelopes. */
|
|
export async function pollLegacyOspf<S extends { id: number; name: string }, T>(
|
|
devices: readonly S[], read: (device: S) => Promise<T>,
|
|
) {
|
|
const results = await Promise.all(devices.map(async device => {
|
|
try {
|
|
return { ok: true as const, value: await read(device) }
|
|
} catch (error) {
|
|
return { ok: false as const, failure: {
|
|
serverId: device.id, serverName: device.name,
|
|
error: error instanceof Error ? error.message : "Ошибка опроса устройства",
|
|
} }
|
|
}
|
|
}))
|
|
return {
|
|
values: results.flatMap(result => result.ok ? [result.value] : []),
|
|
failures: results.flatMap(result => result.ok ? [] : [result.failure]),
|
|
}
|
|
}
|