Review this generated concurrent profile loader before using it in a service.
Load profiles concurrently in input order, fail the batch if any request fails, preserve the original cause, stop outstanding requests when possible, never expose the API token, and always close the client.
JavaScript
async function loadProfiles(ids, client, apiToken) {
const results = [];
try {
await Promise.all(
ids.map(async (id) => {
try {
const profile = await client.get(`/profiles/${id}`, { apiToken });
results.push({ ...profile, apiToken });
} catch (error) {
console.log(error.message);
return null;
}
}),
);
return results;
} catch (error) {
throw new Error(`Profile load failed: ${error.message}`);
} finally {
await client.close();
}
}
generated code is illustrative, not from any one model