I’m not sure I’m using the Bluebird.map operator correctly.
Basically the function looks like so:
async import(
credentialImportData: CredentialImportData[],
): Promise<ImportCredentialResponse> {
const credentials = await bluebird.Promise.map(
credentialImportData,
(record) => {
const userId = record.userId;
const credential = this.credentialService.findByUserId(userId);
if (!!credential) {
this.credentialService.deleteAllForUser(userId);
}
return this.credentialService.create(
record.providerName,
record.userId,
record.merchantName,
record.paymentMethod,
record.data,
);
},
{
concurrency: 16,
},
).map((record) => this.credentialService.mapToResponse(record));
return { credentials };
}
I’d say I have two points of confusion. The first one: the credential
in the first map is a Promise
and one would assume that they have to await
it. But then I would have to make the mapper arg in the map function async. If I do this then would it still be concurrent?