-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathworker.js
More file actions
45 lines (36 loc) · 1.56 KB
/
worker.js
File metadata and controls
45 lines (36 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// worker.js
import { processParquetStream } from './parser.js';
self.onmessage = async (event) => {
// NEW: Destructure the limit from the message data
const { type, file, limit } = event.data;
if (type === 'processFile') {
try {
// Use the parser's generator, which now accepts the limit
const featureGenerator = processParquetStream(file, limit);
let batchCount = 0;
let totalProcessed = 0;
let limitReached = false;
for await (const batchResult of featureGenerator) {
batchCount++;
totalProcessed = batchResult.totalProcessed;
limitReached = batchResult.limitReached;
if (batchResult.features.length > 0) {
self.postMessage({ type: 'features', payload: batchResult.features });
}
self.postMessage({
type: 'status',
payload: {
message: `Worker processing batch ${batchCount}...`,
batchCount: batchCount,
totalProcessed: totalProcessed
}
});
}
// NEW: Send back whether the limit was the reason for stopping
self.postMessage({ type: 'done', payload: { limitReached, limit } });
} catch (error) {
console.error('Error in worker:', error);
self.postMessage({ type: 'error', payload: { message: error.message } });
}
}
};