Skip to content

Commit

Permalink
fixup! Update doc/api/worker_threads.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Ceres6 committed Jan 5, 2025
1 parent c933aaa commit 8944cc0
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions doc/api/worker_threads.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,32 @@ added: REPLACEME

Is `true` if this code is running inside of an internal [`Worker`][] thread (e.g the loader thread).

```js
```bash
node --experimental-loader ./loader.js main.js
```

```cjs
// loader.js
const { isInternalThread } = require('node:worker_threads');
console.log(isInternalThread); // true
```

```mjs
// loader.js
import { isInternalThread } from 'node:worker_threads';
console.log(isInternalThread); // true
```

console.log(isInternalThread); // Prints 'true'.
```cjs
// main.js
const { isInternalThread } = require('node:worker_threads');
console.log(isInternalThread); // false
```

```bash
node --no-warnings --experimental-loader ./loader.js --eval ""
```mjs
// main.js
import { isInternalThread } from 'node:worker_threads';
console.log(isInternalThread); // false
```

## `worker.isMainThread`
Expand Down

0 comments on commit 8944cc0

Please sign in to comment.