SPB Git

Repository Public

worker.ts 3.0 KB 74 lines typescript

1/**2 * =============================================================================3 *                  SP BOUCHER | SOFTWARE & RESEARCH4 *             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project          : KA Maps Engine8 * File             : sdk/web/src/worker.ts9 * Module           : sdk10 * Repository       : https://git.spboucher.ai/ka-maps-engine11 * Created          : 2026-12-0112 * Last Modified    : 2026-12-0113 *14 * Author           : Simon-Pierre Boucher15 * Position         : Professor of Finance16 * Institution      : Université du Québec en Outaouais (UQO)17 * Organization     : SP Boucher18 * Website          : https://spboucher.ai19 * Git              : https://git.spboucher.ai20 *21 * Preferred Contact: support@spboucher.ai22 * Development      : dev@spboucher.ai23 * Support          : support@spboucher.ai24 * Security/Admin   : admin@spboucher.ai25 *26 * Copyright (c) 202627 * Simon-Pierre Boucher28 * All rights reserved where applicable. This file is governed by the29 * applicable project license, copyright notices and relevant law.30 * Existing third-party rights and notices remain unaffected.31 *32 * License          : None specified (no license file in this repository)33 *34 * Do not embed credentials, private keys, access tokens,35 * certificates or confidential personal information.36 *37 * =============================================================================38 * END OF SP BOUCHER SOURCE HEADER39 * =============================================================================40 */4142// Web Worker de construction de tuiles (fichier autonome `ka-maps-worker.js`, script classique).43// Reçoit le WebAssembly.Module déjà compilé par le fil principal, l'instancie, puis construit les44// tuiles demandées. Les tampons voyagent par transfert (aucune copie structurée).4546import { initSync, worker_build, worker_set_style } from './wasm/km_wasm.js';4748type InMsg =49  | { t: 'init'; module: WebAssembly.Module }50  | { t: 'style'; rev: number; document: string }51  | { t: 'build'; job: number; rev: number; z: number; x: number; y: number; bytes: Uint8Array };5253const ctx = self as unknown as { postMessage(msg: unknown, transfer?: Transferable[]): void; onmessage: ((e: MessageEvent<InMsg>) => void) | null };5455ctx.onmessage = (e) => {56  const m = e.data;57  try {58    if (m.t === 'init') {59      initSync({ module: m.module });60      ctx.postMessage({ t: 'ready' });61    } else if (m.t === 'style') {62      worker_set_style(m.rev, m.document);63    } else if (m.t === 'build') {64      const t0 = performance.now();65      const out = worker_build(m.rev, m.z, m.x, m.y, m.bytes);66      ctx.postMessage({ t: 'built', job: m.job, bytes: out, ms: performance.now() - t0 }, [out.buffer]);67    }68  } catch (err) {69    const message = String((err as Error)?.message ?? err);70    if (m.t === 'build') ctx.postMessage({ t: 'failed', job: m.job, message });71    else ctx.postMessage({ t: 'error', message, phase: m.t });72  }73};74
Files main
Menu

Theme