Skip to content

Commit

Permalink
use setImmediate
Browse files Browse the repository at this point in the history
  • Loading branch information
dholms committed Nov 17, 2023
1 parent e8f4acc commit e940c89
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions packages/repo/src/util.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { CID } from 'multiformats/cid'
import { setImmediate } from 'node:timers/promises'
import * as cbor from '@ipld/dag-cbor'
import { CarBlockIterator } from '@ipld/car'
import { BlockWriter, CarWriter } from '@ipld/car/writer'
Expand All @@ -11,7 +12,6 @@ import {
cidForCbor,
byteIterableToStream,
TID,
wait,
} from '@atproto/common'
import { ipldToLex, lexToIpld, LexValue, RepoRecord } from '@atproto/lexicon'

Expand Down Expand Up @@ -102,13 +102,10 @@ export const carToBlocks = async (
}
const blocks = new BlockMap()
if (car._iterable) {
let count = 0
for await (const block of car._iterable) {
blocks.set(block.cid, block.bytes)
count++
if (count % 10000 === 0) {
await wait(1)
}
// break up otherwise "synchronous" work
await setImmediate()
}
}
return {
Expand Down

0 comments on commit e940c89

Please sign in to comment.