⚡ Zero-dependency plcbundle library exclusively for Bun
at main 1.1 kB view raw
1/** 2 * Example: Process bundles in parallel with multiple threads 3 * 4 * Usage: 5 * bun examples/parallel.ts 6 */ 7 8import { PLCBundle } from '../src'; 9 10const bundle = new PLCBundle('./data/bundles'); 11 12console.log('Processing bundles 1-50 with 4 threads...\n'); 13 14const matches = { 15 withHandle: 0, 16 withPds: 0, 17}; 18 19const startTime = Date.now(); 20 21await bundle.processBundles(1, 50, (op, position, bundleNum, line) => { 22 if (op.operation?.alsoKnownAs?.length > 0) { 23 matches.withHandle++; 24 } 25 26 if (op.operation?.services?.atproto_pds) { 27 matches.withPds++; 28 } 29}, { 30 threads: 4, 31 onProgress: (stats) => { 32 const elapsed = (Date.now() - startTime) / 1000; 33 const opsPerSec = (stats.totalOps / elapsed).toFixed(0); 34 35 process.stdout.write( 36 `Processed ${stats.totalOps} ops | ${opsPerSec} ops/sec\r` 37 ); 38 } 39}); 40 41const elapsed = (Date.now() - startTime) / 1000; 42 43console.log('\n'); 44console.log('✓ Processing complete'); 45console.log(` With handle: ${matches.withHandle.toLocaleString()}`); 46console.log(` With PDS: ${matches.withPds.toLocaleString()}`); 47console.log(` Time: ${elapsed.toFixed(2)}s`);