-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathworker.js
More file actions
30 lines (26 loc) · 702 Bytes
/
worker.js
File metadata and controls
30 lines (26 loc) · 702 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
const { parentPort } = require('worker_threads')
const pynode = require('./build/Release/PyNode')
const longRunningFunction = () => {
return new Promise((resolve, reject) => {
console.log('cwd : ', process.cwd())
pynode.startInterpreter()
pynode.appendSysPath('./test_files')
pynode.openFile('performance')
pynode.call('generate_slow_number', 5, 7, (err, result) => {
if (err) {
reject(err)
return
}
resolve(result)
})
})
}
longRunningFunction()
.then(result => {
console.log('result : ', result)
parentPort.postMessage(result)
})
.catch(e => {
console.log('err : ', e)
parentPort.postMessage({error: e})
})