From 52c74a1c33ce12b93ec5830f5a6348d9578c7c6e Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Thu, 5 Jun 2025 08:37:34 +0200 Subject: Simplify callback business (web version) --- web/http/start-server.sh | 8 ++++++++ web/http/worker.mjs | 14 ++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) create mode 100755 web/http/start-server.sh (limited to 'web/http') diff --git a/web/http/start-server.sh b/web/http/start-server.sh new file mode 100755 index 0000000..c827146 --- /dev/null +++ b/web/http/start-server.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +# Run this script from the main folder (../../) + +darkhttpd web/http \ + --header 'Cross-Origin-Opener-Policy: same-origin' \ + --header 'Cross-Origin-Embedder-Policy: require-corp' \ + --mimetypes web/http/mime diff --git a/web/http/worker.mjs b/web/http/worker.mjs index d912e8b..0c1acb9 100644 --- a/web/http/worker.mjs +++ b/web/http/worker.mjs @@ -1,14 +1,16 @@ import Nissy from "./nissy_web_module.mjs" const nissy = await Nissy(); -const log = (msg) => postMessage({ command: "log", id: -1, object: msg }); -nissy.setLogger(nissy._addCallbackFunction(log)); -var solveStatus = nissy.statusRUN; // For now this is a global variable -const pollStatusCallback = nissy._addCallbackFunction(() => { -console.log("Calling pollstatus, returning " + solveStatus); -return solveStatus; +const log = (cstr) => postMessage({ + command: "log", id: -1, + object: nissy.UTF8ToString(cstr) }); +nissy.setLogger(nissy.addFunction(log, "vp")); + +var solveStatus = nissy.statusRUN; // For now this is a global variable +const pollStatus = () => solveStatus; +const pollStatusCallback = nissy.addFunction(pollStatus, "i"); const commands = [ { name: "load solver data", exec: loadSolverDataFromStorage }, -- cgit v1.3