vlt / docs

  • PricingBenchmarks (opens in new window)Community (opens in new window)Feedback
  • Overview
    • Overview
    • clonefile
    • link-tree
    • index
    • placement-pool
    • placement-worker
    • pool
    • Reference
    • store-entry
    • store-index
    • unpack
  • Type Aliases
  • CacheEntryJob
  • PlacementJob
  • PlacementReply
  • ReplyPort
  • UnpackJob
  • Variables
  • __CODE_SPLIT_SCRIPT_NAME
  • Functions
  • handleJob()
  1. Client
  2. /
  3. API Reference
  4. /
  5. @vltpkg/tar
  6. /
  7. placement-worker

placement-worker

Type Aliases

CacheEntryJob

TypeScript
type CacheEntryJob = object;

Defined in: tar/src/placement-worker.ts:46

Unpack the tarball in a vlt cache entry file into target. The worker reads the file itself, so the main thread never holds or copies the body.

Type declaration

NameType
filestring
format?TarballFormat
idnumber
kind"cacheEntry"
targetstring

PlacementJob

TypeScript
type PlacementJob = 
  | UnpackJob
  | CacheEntryJob;

Defined in: tar/src/placement-worker.ts:54


PlacementReply

TypeScript
type PlacementReply = 
  | {
  id: number;
  result: true;
 }
  | {
  code: string;
  error: string;
  id: number;
  stack: string;
 }
  | {
  ready: true;
};

Defined in: tar/src/placement-worker.ts:61

A worker's reply for job id: true once unpacked, or the message, stack and errno code of the error thrown, which the pool rebuilds into an Error so a worker failure looks like the inline call failing.

Type declaration

{ id: number; result: true; }

NameType
idnumber
resulttrue

{ code: string; error: string; id: number; stack: string; }

NameType
code?string
errorstring
idnumber
stack?string

{ ready: true; }

NameType
readytrue

ReplyPort

TypeScript
type ReplyPort = object;

Defined in: tar/src/placement-worker.ts:68

A port that takes a PlacementReply; the real one is parentPort.

Type declaration

NameType
postMessage(reply) => void

UnpackJob

TypeScript
type UnpackJob = object;

Defined in: tar/src/placement-worker.ts:31

Unpack a tarball into target. The bytes arrive as an ArrayBuffer transferred from the main thread.

Type declaration

NameType
bufferArrayBuffer
byteLengthnumber
byteOffsetnumber
format?TarballFormat
idnumber
kind"unpack"
targetstring

Variables

__CODE_SPLIT_SCRIPT_NAME

TypeScript
const __CODE_SPLIT_SCRIPT_NAME: string;

Defined in: tar/src/placement-worker.ts:25

Unpacking a tarball is synchronous work the main thread cannot afford: inflating it, parsing it and writing its files. While the main thread does that, no registry response is read, no manifest is parsed and no node is placed in the graph. A PlacementPool runs this script as a worker thread so several packages are unpacked at once, across cores, and the main thread stays free to keep the network busy.

Hardlinking a global store entry stays on the main thread: it is a fraction of a millisecond per package, and on a two-core machine the boot of the workers and the round trips never paid for themselves (measured: +48% on the placement phase of a warm install).

The build emits it as its own bundled file: the exported __CODE_SPLIT_SCRIPT_NAME is the path to spawn (the source .ts in dev and test, the built .js in the bundle), and handleJob is the per-message handler, exported so it can be tested without a live worker.

Functions

handleJob()

TypeScript
function handleJob(port, job): void

Defined in: tar/src/placement-worker.ts:73

Run one job and post the result (or its error) back.

Parameters

ParameterType
portReplyPort
jobPlacementJob

Returns

void


Previousplacement-poolNextpool

On this page

  • Type Aliases
  • CacheEntryJob
  • PlacementJob
  • PlacementReply
  • ReplyPort
  • UnpackJob
  • Variables
  • __CODE_SPLIT_SCRIPT_NAME
  • Functions
  • handleJob()

Deploy your package on vlt.io

Publish scoped and private packages, manage organizations and access, and give every developer and CI environment a consistent source for public and private JavaScript dependencies.

Publish now