Skip to content

Commit 0d7f5d9

Browse files
committed
fix(samples): backend-nodejs-wasm-multithread — migrate to new target API
Same surgical migration as matrix-mt + the await pattern. This sample was untouched by Group 3 because it's a CLI sample, not browser; only surfaced when running it on the command line. - cppjs.config.mjs: build.usePthread → target.runtime: 'mt' - package.json script: -p WebAssembly → -p wasm -a wasm32 -r mt -e node -b release (mirrors the st sibling's flags but with -r mt) - src/index.mjs: - Update the dist import path to the target-system naming (cppjs-sample-backend-nodejs-wasm-multithread-wasm-wasm32-mt-release.node.js). - await Native.sample()/runOnThread()/getThreadResult() — comlink proxies the worker calls. - Move getThreadResult() into setTimeout's async callback so the thread has time to finish. Verified: `node src/index.mjs` prints both the standard result and the thread-computed result.
1 parent 88312f8 commit 0d7f5d9

3 files changed

Lines changed: 9 additions & 9 deletions

File tree

cppjs-samples/cppjs-sample-backend-nodejs-wasm-multithread/cppjs.config.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default {
1212
base: '../..', /* Delete this line for create-cpp.js */
1313
output: 'dist',
1414
},
15-
build: {
16-
usePthread: true
15+
target: {
16+
runtime: 'mt',
1717
}
1818
};

cppjs-samples/cppjs-sample-backend-nodejs-wasm-multithread/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"repository": "https://github.com/bugra9/cpp.js.git",
77
"license": "MIT",
88
"scripts": {
9-
"build": "cppjs build -p WebAssembly"
9+
"build": "cppjs build -p wasm -a wasm32 -r mt -e node -b release"
1010
},
1111
"dependencies": {
1212
"cpp.js": "workspace:^",
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import initCppJs from '../dist/cppjs-sample-backend-nodejs-wasm.node.js';
1+
import initCppJs from '../dist/cppjs-sample-backend-nodejs-wasm-multithread-wasm-wasm32-mt-release.node.js';
22

3-
initCppJs().then(({ Native }) => {
4-
console.log(`Matrix multiplier with c++ => ${Native.sample()}`);
5-
Native.runOnThread();
6-
setTimeout(() => {
7-
console.log(`Thread result: ${Native.getThreadResult()}`);
3+
initCppJs().then(async ({ Native }) => {
4+
console.log(`Matrix multiplier with c++ => ${await Native.sample()}`);
5+
await Native.runOnThread();
6+
setTimeout(async () => {
7+
console.log(`Thread result: ${await Native.getThreadResult()}`);
88
}, 1000);
99
});

0 commit comments

Comments
 (0)