Skip to content

Commit

Permalink
add reference to piscina
Browse files Browse the repository at this point in the history
  • Loading branch information
kentcdodds committed Nov 30, 2022
1 parent b992d04 commit 7b3fec3
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/threads.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

For most applications, `better-sqlite3` is fast enough to use in the main thread without blocking for a noticeable amount of time. However, if you need to perform very slow queries, you have the option of using [worker threads](https://nodejs.org/api/worker_threads.html) to keep things running smoothly. Below is an example of using a thread pool to perform queries in the background.

NOTE: The example below is nice for simple use cases, but if you're going to do anything much more complex, then you may want to look into a proper worker library like [piscina](https://github.com/piscinajs/piscina).

### worker.js

The worker logic is very simple in our case. It accepts messages from the master thread, executes each message's SQL (with any given parameters), and sends back the query results.
Expand Down

0 comments on commit 7b3fec3

Please sign in to comment.