solver-worker.ts 556 B

12345678910111213141516171819
  1. import type { CachedResult } from '@wordle/shared';
  2. import { computeReplays, computeReplaysFull } from '@wordle/shared';
  3. interface SolverTask {
  4. target: string;
  5. allWords: string[];
  6. mode: 'fast' | 'full';
  7. }
  8. process.on('message', (task: SolverTask) => {
  9. try {
  10. const result: CachedResult = task.mode === 'full'
  11. ? computeReplaysFull(task.target, task.allWords)
  12. : computeReplays(task.target, task.allWords);
  13. process.send!({ ok: true, value: result });
  14. } catch (err) {
  15. process.send!({ ok: false, error: String(err) });
  16. }
  17. });