Skip to content

Commit

Permalink
⚡ use Promise.all
Browse files Browse the repository at this point in the history
  • Loading branch information
vikiival committed Oct 14, 2024
1 parent e59f60e commit 3ec3b80
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion services/ipos/src/routes/pinning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,13 @@ app.post('/pinFile', vValidator('form', pinFileRequestSchema), async (c) => {
},
})

const promises: Promise<R2Object | null>[] = []
for (const { file } of files) {
const path = `${cid}/${file.name}`
c.executionCtx.waitUntil(c.env.BUCKET.put(keyOf(path), file))
promises.push(c.env.BUCKET.put(keyOf(path), file))
}

c.executionCtx.waitUntil(Promise.allSettled(promises))
} else {
const { content, file: f } = files[0]
cid = (await hashOf(content)).toV0().toString()
Expand Down

0 comments on commit 3ec3b80

Please sign in to comment.