1 | const { create, all } = require('../../..')
|
2 | const workerpool = require('workerpool')
|
3 | const math = create(all)
|
4 |
|
5 | // disable the import function so the math.js instance cannot be changed
|
6 | function noImport () {
|
7 | throw new Error('function import is disabled.')
|
8 | }
|
9 | math.import({ import: noImport }, { override: true })
|
10 |
|
11 | /**
|
12 | * Evaluate an expression
|
13 | * @param {string} expr
|
14 | * @return {string} result
|
15 | */
|
16 | function evaluate (expr) {
|
17 | const ans = math.evaluate(expr)
|
18 | return math.format(ans)
|
19 | }
|
20 |
|
21 | // create a worker and register public functions
|
22 | workerpool.worker({
|
23 | evaluate: evaluate
|
24 | })
|