You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: docs/threads.md
+2
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,8 @@
2
2
3
3
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.
4
4
5
+
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).
6
+
5
7
### worker.js
6
8
7
9
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.
0 commit comments