From 9fbb9880d220bc1c2dcd1d92162075e965f77b31 Mon Sep 17 00:00:00 2001 From: Tim Sekiguchi Date: Wed, 8 Jan 2025 23:36:42 -0800 Subject: [PATCH] docs: update page titles / positions in docs (#727) --- docs/docs/examples/broadcast.mdx | 2 +- docs/docs/examples/electron.mdx | 2 +- docs/docs/examples/es-module.mdx | 2 +- docs/docs/examples/message-port.mdx | 2 +- docs/docs/examples/messages.mdx | 2 +- docs/docs/examples/move.mdx | 2 +- .../examples/multiple-workers-one-file.mdx | 2 +- docs/docs/examples/multiple-workers.mdx | 2 +- docs/docs/examples/n-api.mdx | 2 +- docs/docs/examples/named.mdx | 2 +- docs/docs/examples/progress.mdx | 2 +- docs/docs/examples/react-ssr.mdx | 2 +- docs/docs/examples/resource-limit.mdx | 2 +- docs/docs/examples/scrypt.mdx | 2 +- docs/docs/examples/server.mdx | 2 +- docs/docs/examples/simple.mdx | 2 +- docs/docs/examples/simple_async.mdx | 2 +- docs/docs/examples/stream-in.mdx | 2 +- docs/docs/examples/stream.mdx | 2 +- docs/docs/examples/task-queue.mdx | 2 +- docs/docs/examples/typescript.md | 81 ------------------- docs/docs/examples/webstreams-transform.mdx | 2 +- docs/docs/examples/webstreams.mdx | 2 +- docs/docs/examples/worker-options.mdx | 2 +- .../managing-worker-threads.mdx | 2 +- .../typescript.mdx | 2 +- 26 files changed, 25 insertions(+), 106 deletions(-) delete mode 100644 docs/docs/examples/typescript.md rename docs/docs/{examples => getting-started}/typescript.mdx (99%) diff --git a/docs/docs/examples/broadcast.mdx b/docs/docs/examples/broadcast.mdx index d1e26770..26da7d6d 100644 --- a/docs/docs/examples/broadcast.mdx +++ b/docs/docs/examples/broadcast.mdx @@ -1,6 +1,6 @@ --- id: Broadcast -sidebar_position: 23 +sidebar_position: 3 --- import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; diff --git a/docs/docs/examples/electron.mdx b/docs/docs/examples/electron.mdx index 9a0f2618..72f9fba5 100644 --- a/docs/docs/examples/electron.mdx +++ b/docs/docs/examples/electron.mdx @@ -1,5 +1,5 @@ --- -id: Worker Options +id: Electron sidebar_position: 4 --- diff --git a/docs/docs/examples/es-module.mdx b/docs/docs/examples/es-module.mdx index 3072ffce..c988dd90 100644 --- a/docs/docs/examples/es-module.mdx +++ b/docs/docs/examples/es-module.mdx @@ -1,6 +1,6 @@ --- id: ES Module -sidebar_position: 3 +sidebar_position: 5 --- import { WorkerWrapperComponent } from "@site/src/components/WorkerWrapper.mdx"; diff --git a/docs/docs/examples/message-port.mdx b/docs/docs/examples/message-port.mdx index ed6c7d30..27b4bb34 100644 --- a/docs/docs/examples/message-port.mdx +++ b/docs/docs/examples/message-port.mdx @@ -1,6 +1,6 @@ --- id: Message Port -sidebar_position: 4 +sidebar_position: 6 --- import { WorkerWrapperComponent } from "@site/src/components/WorkerWrapper.mdx"; diff --git a/docs/docs/examples/messages.mdx b/docs/docs/examples/messages.mdx index f86efd13..b774ef48 100644 --- a/docs/docs/examples/messages.mdx +++ b/docs/docs/examples/messages.mdx @@ -1,6 +1,6 @@ --- id: Messages -sidebar_position: 5 +sidebar_position: 7 --- import { WorkerWrapperComponent } from "@site/src/components/WorkerWrapper.mdx"; diff --git a/docs/docs/examples/move.mdx b/docs/docs/examples/move.mdx index feb91f53..c3adb569 100644 --- a/docs/docs/examples/move.mdx +++ b/docs/docs/examples/move.mdx @@ -1,6 +1,6 @@ --- id: Move -sidebar_position: 6 +sidebar_position: 8 --- import { WorkerWrapperComponent } from "@site/src/components/WorkerWrapper.mdx"; diff --git a/docs/docs/examples/multiple-workers-one-file.mdx b/docs/docs/examples/multiple-workers-one-file.mdx index 80c447e4..278e615d 100644 --- a/docs/docs/examples/multiple-workers-one-file.mdx +++ b/docs/docs/examples/multiple-workers-one-file.mdx @@ -1,6 +1,6 @@ --- id: Multiple Workers in One File -sidebar_position: 8 +sidebar_position: 9 --- import { WorkerWrapperComponent } from "@site/src/components/WorkerWrapper.mdx"; diff --git a/docs/docs/examples/multiple-workers.mdx b/docs/docs/examples/multiple-workers.mdx index c6782349..f1ec25ff 100644 --- a/docs/docs/examples/multiple-workers.mdx +++ b/docs/docs/examples/multiple-workers.mdx @@ -1,6 +1,6 @@ --- id: Multiple Workers -sidebar_position: 7 +sidebar_position: 10 --- import { WorkerWrapperComponent } from "@site/src/components/WorkerWrapper.mdx"; diff --git a/docs/docs/examples/n-api.mdx b/docs/docs/examples/n-api.mdx index 6be34d3b..5e52dc51 100644 --- a/docs/docs/examples/n-api.mdx +++ b/docs/docs/examples/n-api.mdx @@ -1,6 +1,6 @@ --- id: N-API Native Addon -sidebar_position: 9 +sidebar_position: 11 --- For CPU-intensive tasks or when implementing workers in languages such as C++ or Rust, you can leverage Piscina's support for native addons as worker implementations. diff --git a/docs/docs/examples/named.mdx b/docs/docs/examples/named.mdx index 4e1a2e74..7c14fbc4 100644 --- a/docs/docs/examples/named.mdx +++ b/docs/docs/examples/named.mdx @@ -1,6 +1,6 @@ --- id: Named Tasks -sidebar_position: 10 +sidebar_position: 12 --- import { WorkerWrapperComponent } from "@site/src/components/WorkerWrapper.mdx"; diff --git a/docs/docs/examples/progress.mdx b/docs/docs/examples/progress.mdx index 1e611bb2..2837ed57 100644 --- a/docs/docs/examples/progress.mdx +++ b/docs/docs/examples/progress.mdx @@ -1,6 +1,6 @@ --- id: Progress -sidebar_position: 11 +sidebar_position: 13 --- import {WorkerWrapperComponent} from '@site/src/components/WorkerWrapper.mdx'; diff --git a/docs/docs/examples/react-ssr.mdx b/docs/docs/examples/react-ssr.mdx index a00f195d..f7661619 100644 --- a/docs/docs/examples/react-ssr.mdx +++ b/docs/docs/examples/react-ssr.mdx @@ -1,6 +1,6 @@ --- id: React Server Side Rendering -sidebar_position: 12 +sidebar_position: 14 --- import Tabs from "@theme/Tabs"; import TabItem from "@theme/TabItem"; diff --git a/docs/docs/examples/resource-limit.mdx b/docs/docs/examples/resource-limit.mdx index 42b967ca..f425ed77 100644 --- a/docs/docs/examples/resource-limit.mdx +++ b/docs/docs/examples/resource-limit.mdx @@ -1,6 +1,6 @@ --- id: Resource Limits -sidebar_position: 12 +sidebar_position: 15 --- import Tabs from '@theme/Tabs'; diff --git a/docs/docs/examples/scrypt.mdx b/docs/docs/examples/scrypt.mdx index 86f52efb..4a52c06e 100644 --- a/docs/docs/examples/scrypt.mdx +++ b/docs/docs/examples/scrypt.mdx @@ -1,6 +1,6 @@ --- id: Scrypt -sidebar_position: 13 +sidebar_position: 16 --- import Tabs from '@theme/Tabs'; diff --git a/docs/docs/examples/server.mdx b/docs/docs/examples/server.mdx index 38529001..aeb96b80 100644 --- a/docs/docs/examples/server.mdx +++ b/docs/docs/examples/server.mdx @@ -1,6 +1,6 @@ --- id: Server -sidebar_position: 14 +sidebar_position: 17 --- The benefit of offloading work to a worker pool will vary significantly diff --git a/docs/docs/examples/simple.mdx b/docs/docs/examples/simple.mdx index 13e7436a..abd9ff7a 100644 --- a/docs/docs/examples/simple.mdx +++ b/docs/docs/examples/simple.mdx @@ -1,6 +1,6 @@ --- id: Simple -sidebar_position: 15 +sidebar_position: 19 --- import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; diff --git a/docs/docs/examples/simple_async.mdx b/docs/docs/examples/simple_async.mdx index c9574b45..ebb19d82 100644 --- a/docs/docs/examples/simple_async.mdx +++ b/docs/docs/examples/simple_async.mdx @@ -1,6 +1,6 @@ --- id: Simple Async -sidebar_position: 16 +sidebar_position: 18 --- import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; diff --git a/docs/docs/examples/stream-in.mdx b/docs/docs/examples/stream-in.mdx index 793364e2..3643c0a3 100644 --- a/docs/docs/examples/stream-in.mdx +++ b/docs/docs/examples/stream-in.mdx @@ -1,6 +1,6 @@ --- id: Stream-In -sidebar_position: 17 +sidebar_position: 20 --- import Tabs from '@theme/Tabs'; diff --git a/docs/docs/examples/stream.mdx b/docs/docs/examples/stream.mdx index 5dce9c31..878b618d 100644 --- a/docs/docs/examples/stream.mdx +++ b/docs/docs/examples/stream.mdx @@ -1,6 +1,6 @@ --- id: Stream -sidebar_position: 16 +sidebar_position: 21 --- import Tabs from '@theme/Tabs'; diff --git a/docs/docs/examples/task-queue.mdx b/docs/docs/examples/task-queue.mdx index c746abf0..d3875c3c 100644 --- a/docs/docs/examples/task-queue.mdx +++ b/docs/docs/examples/task-queue.mdx @@ -1,6 +1,6 @@ --- id: Task Queue -sidebar_position: 18 +sidebar_position: 22 --- import {WorkerWrapperComponent} from '@site/src/components/WorkerWrapper.mdx'; diff --git a/docs/docs/examples/typescript.md b/docs/docs/examples/typescript.md deleted file mode 100644 index 34f874fc..00000000 --- a/docs/docs/examples/typescript.md +++ /dev/null @@ -1,81 +0,0 @@ ---- -id: Using Typescript with Piscina -sidebar_position: 2 ---- -import {WorkerWrapperComponent} from '@site/src/components/WorkerWrapper.mdx'; - -Although Piscina itself is written in TypeScript and supports TypeScript out of the box, complication arises when trying to use `.ts` files directly as worker files because Node.js does not support TypeScript natively. - -To work around this, you would typically need to compile your TypeScript worker files to JavaScript first, and then point Piscina’s `filename` option to the compiled JavaScript files. Consider the following methods: - -## Method 1: Using a Worker Wrapper File and `ts_node` - -The worker wrapper checks if the provided file path ends with `.ts` and registers the `ts-node` compiler to handle TypeScript files. - - - -In your `worker.ts`: - -```typescript title='worker.ts' - -import { resolve } from 'path'; - -export const filename = resolve(__filename); - -interface Inputs { - a: number; - b: number; -} - -export function addNumbers({ a, b }: Inputs): number { - return a + b; -} -``` - -Inside the main application: - -```typescript title='main.ts' - -import Piscina from 'piscina'; -import { resolve } from 'path'; -import { filename } from './worker'; - -const piscina = new Piscina({ - filename: resolve(__dirname, './workerWrapper.js'), - workerData: { fullpath: filename }, -}); - -(async () => { - const result = await piscina.run({ a: 2, b: 3 }, { name: 'addNumbers' }); - console.log('Result:', result); -})(); -``` - -## Method 2: Inline Worker Code - -Alternatively, you can include the worker code in the same file as your main code and use the `isMainThread` flag from `worker_threads` to determine whether the code is running in the main thread or the worker thread. - -```typescript title="main.ts" - -import Piscina from 'piscina'; -import { isMainThread } from 'worker_threads'; - -interface Inputs { - a: number; - b: number; -} - -if (isMainThread) { - const piscina = new Piscina({ filename: __filename }); - - (async () => { - const task: Inputs = { a: 1, b: 2 }; - console.log(await piscina.run(task)); - })(); -} else { - export default ({ a, b }: Inputs): number => { - return a + b; - }; -} -``` -You can also check out this example on [github](https://github.com/piscinajs/piscina/tree/current/examples/typescript). \ No newline at end of file diff --git a/docs/docs/examples/webstreams-transform.mdx b/docs/docs/examples/webstreams-transform.mdx index 04c0bfbf..cbbc6b34 100644 --- a/docs/docs/examples/webstreams-transform.mdx +++ b/docs/docs/examples/webstreams-transform.mdx @@ -1,6 +1,6 @@ --- id: Web Streams Transfer -sidebar_position: 21 +sidebar_position: 24 --- import {WorkerWrapperComponent} from '@site/src/components/WorkerWrapper.mdx'; diff --git a/docs/docs/examples/webstreams.mdx b/docs/docs/examples/webstreams.mdx index cb6fc5fc..e2072436 100644 --- a/docs/docs/examples/webstreams.mdx +++ b/docs/docs/examples/webstreams.mdx @@ -1,6 +1,6 @@ --- id: Web Streams -sidebar_position: 20 +sidebar_position: 25 --- import {WorkerWrapperComponent} from '@site/src/components/WorkerWrapper.mdx'; diff --git a/docs/docs/examples/worker-options.mdx b/docs/docs/examples/worker-options.mdx index 0d2bc50d..4044e99d 100644 --- a/docs/docs/examples/worker-options.mdx +++ b/docs/docs/examples/worker-options.mdx @@ -1,6 +1,6 @@ --- id: Worker Options -sidebar_position: 22 +sidebar_position: 26 --- import {WorkerWrapperComponent} from '@site/src/components/WorkerWrapper.mdx'; diff --git a/docs/docs/getting-started/managing-worker-threads.mdx b/docs/docs/getting-started/managing-worker-threads.mdx index 796e7252..883bbc88 100644 --- a/docs/docs/getting-started/managing-worker-threads.mdx +++ b/docs/docs/getting-started/managing-worker-threads.mdx @@ -1,6 +1,6 @@ --- id: Managing Worker Threads -sidebar_position: 2 +sidebar_position: 3 --- import {WorkerWrapperComponent} from '@site/src/components/WorkerWrapper.mdx'; import Tabs from "@theme/Tabs"; diff --git a/docs/docs/examples/typescript.mdx b/docs/docs/getting-started/typescript.mdx similarity index 99% rename from docs/docs/examples/typescript.mdx rename to docs/docs/getting-started/typescript.mdx index 24a82d8c..962fa415 100644 --- a/docs/docs/examples/typescript.mdx +++ b/docs/docs/getting-started/typescript.mdx @@ -1,6 +1,6 @@ --- id: Typescript -sidebar_position: 19 +sidebar_position: 4 --- import {WorkerWrapperComponent} from '@site/src/components/WorkerWrapper.mdx';