Open dmeehan1968 opened 12 months ago
I realised that I should probably be using Promise.all
(if I was writing typescript) but this produces an error:
const migratedItems = await Promise.all(await asl.map({
items: scanResult.Items,
iterator: async (item) => {
return await migrateItem(item)
},
}))
Error:
Error: promise.all statement must have array literal expression as argument
Kind: CallExpression
Source: Promise.all(await asl.map({
items: scanResult.Items,
iterator: async (item) => {
return await migrateItem(item)
},
}))
This seems at odds with:
await asl.sdk(DynamoDB).batchWriteItem({
parameters: {
RequestItems: {
'MyTableName': await Promise.all(scanResult.Items.map(async (item) => ({
PutRequest: {
Item: await migrateItem(item),
}
})))
}
}
})
Note #911 prevents use of a computed table name.
The difference between asl.map
and Array.map
is that the former allows for concurrency control via the maxConcurrency
property, whilst the latter uses Map defaults, which is unconstrained concurrency. Not being able to wrap asl.map
in Promise.all
means that there is no option to control concurrency.
Example code
If
migrateItem()
is defined asmigrateItem(item: Record<string, AttributeValue>): Promise<Record<string, AttributeValue>> {...}
, then the return type fromasl.map
isPromise<Promise<Record<string, AttributeValue>>[]>
(promise for array of promises). In the example code, another await would be required to resolve back to the actual resolved value.It seems that the definition of
Map<Input,Output>
'siterator
is incorrect in not mentioningPromise
. The following definition produces the correct output (paraphrased) whilst allowing the iterator to be async or not.It may be possible to force the correct type using coercion (as a workaround):