import { DbWorker } from './workers/DbWorker.js';
import { readUint64 } from '@saulx/utils';
export class QueryWorker extends DbWorker {
    constructor(address, db, workerIndex) {
        const onExit = (_code) => {
            this.db.workers[workerIndex] = new QueryWorker(address, db, workerIndex);
        };
        super(address, db, onExit, 'query_worker.js');
    }
    handleMsg(_buf) {
        this.db.activeReaders--;
        this.db.onQueryEnd();
    }
    callback = (resolve) => {
        this.db.activeReaders++;
        this.resolvers.push(resolve);
    };
    getQueryBuf(buf) {
        const schemaChecksum = readUint64(buf, buf.byteLength - 8);
        if (schemaChecksum !== this.db.schema?.hash) {
            return Promise.resolve(new Uint8Array(1));
        }
        return this.call(buf);
    }
}
//# sourceMappingURL=QueryWorker.js.map