forked from fridgerator/PyNode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworker.js
More file actions
30 lines (26 loc) · 730 Bytes
/
worker.js
File metadata and controls
30 lines (26 loc) · 730 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
import { parentPort } from 'worker_threads'
import { pynode } from "./index.js"
const longRunningFunction = () => {
return new Promise((resolve, reject) => {
console.log('cwd : ', process.cwd())
pynode.startInterpreter()
pynode.appendSysPath('./test_files')
const performance = pynode.openFile('performance')
performance.__getattr__('generate_slow_number').__callasync__(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})
})