Skip to content

Commit

Permalink
fix: load piscina only if available
Browse files Browse the repository at this point in the history
Signed-off-by: Tuan Anh Tran <me@tuananh.org>
  • Loading branch information
tuananh committed Jan 31, 2021
1 parent 5402620 commit c46c1b1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Expand Up @@ -9,7 +9,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
node-version: [12.x, 13.x, 14.x, 15.x]
node-version: [10.x, 11.x, 12.x, 13.x, 14.x, 15.x]
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v2
Expand Down
16 changes: 14 additions & 2 deletions index.js
@@ -1,7 +1,19 @@
const { resolve } = require('path')
const WorkerPool = require('piscina')

const pool = new WorkerPool({ filename: resolve(__dirname, 'worker.js') })
let pool = null
try {
const WorkerPool = require('piscina')
pool = new WorkerPool({ filename: resolve(__dirname, 'worker.js') })
} catch(e) {
if (e.code === 'MODULE_NOT_FOUND') {
console.warn('[camaro] worker_threads is not available, expect performance drop. Try using Node version >= 12.')
}

const workerFn = require('./worker')
pool = {
runTask: async (args) => workerFn(args)
}
}

function isNonEmptyString(str) {
return typeof str === 'string' && str.length > 0
Expand Down

0 comments on commit c46c1b1

Please sign in to comment.