multithread
Advanced tools
Comparing version 0.0.2 to 0.0.3
15
api.js
let console = { | ||
"log": (msg) => { | ||
_API_consoleLog(msg.toString()); | ||
}, | ||
"error": (msg) => { | ||
_API_consoleLog("[ERROR] " + msg.toString()); | ||
}, | ||
"info": (msg) => { | ||
_API_consoleLog("[INFO] " + msg.toString()); | ||
} | ||
} | ||
let sharedVariables = { | ||
"set": (k, v) => { | ||
_API_setSharedVariableValue(k.toString(), v.toString()); | ||
}, | ||
"get": (k) => { | ||
return _API_getSharedVariableValue(k.toString()); | ||
} | ||
} |
10
core.js
@@ -7,7 +7,11 @@ const coreLib = require("./build/Release/MultithreadCore"); | ||
function createThread(name, scriptPath) { | ||
function createThread(name, scriptPath, cb) { | ||
let scriptCode = fs.readFileSync(scriptPath, "utf-8"); | ||
if(!cb) cb = () => {}; | ||
coreLib.createThread( | ||
name, | ||
initializerCode + scriptCode | ||
initializerCode + scriptCode, | ||
cb | ||
); | ||
@@ -17,1 +21,3 @@ } | ||
module.exports.createThread = createThread; | ||
module.exports.getSharedVariableValue = coreLib.getSharedVariableValue; | ||
module.exports.setSharedVariableValue = coreLib.setSharedVariableValue; |
{ | ||
"name": "multithread", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "Multithread for Node", | ||
@@ -5,0 +5,0 @@ "main": "core.js", |
11
test.js
const multithread = require("./core.js"); | ||
multithread.createThread("testThread1", "./testWorker.js"); | ||
multithread.createThread("testThread2", "./testWorker.js"); | ||
setTimeout(() => process.exit(0), 1000); | ||
multithread.createThread("testThread1", "./testWorker.js", () => { | ||
console.log(multithread.getSharedVariableValue("output")); | ||
}); | ||
multithread.createThread("testThread2", "./testWorker.js", () => { | ||
console.log(multithread.getSharedVariableValue("output")); | ||
}); | ||
console.log("Threads created"); |
@@ -0,1 +1,3 @@ | ||
console.log("Thread started"); | ||
let startTime = Date.now(); | ||
@@ -5,11 +7,11 @@ | ||
for(let i = 0; i < 100000; i++) result += Math.random(); | ||
for(let i = 0; i < 10000000; i++) result += Math.random(); | ||
let endTime = Date.now(); | ||
console.log(JSON.stringify({ | ||
let output = JSON.stringify({ | ||
"result": result, | ||
"time": endTime - startTime | ||
})); | ||
}); | ||
console.log("Worker done"); | ||
sharedVariables.set("output", output); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12271
15
53