Options
All
  • Public
  • Public/Protected
  • All
Menu

The DenoWorker class is a WebWorker-like interface for interacting with Deno.

Because Deno is an isolated environment, this worker gives you the ability to run untrusted JavaScript code without potentially compromising your system.

Hierarchy

  • DenoWorker

Index

Constructors

constructor

  • Creates a new DenoWorker instance and injects the given script.

    Parameters

    • script: string | URL

      The JavaScript that the worker should be started with.

    • Optional options: Partial<DenoWorkerOptions>

    Returns DenoWorker

Properties

Private _available

_available: boolean

Private _httpServer

_httpServer: Server

Private _onexitListeners

_onexitListeners: OnExitListener[]

Private _onmessageListeners

_onmessageListeners: OnMessageListener[]

Private _options

Private _pendingMessages

_pendingMessages: string[]

Private _ports

_ports: Map<number | string, MessagePortData>

Private _process

_process: ChildProcess

Private _server

_server: WSServer

Private _socket

_socket: WebSocket

Private _socketClosed

_socketClosed: boolean

Private _stderr

_stderr: Readable

Private _stdout

_stdout: Readable

Private _terminated

_terminated: boolean

onexit

onexit: (code: number, signal: string) => void = null

Represents an event handler for the "exit" event. That is, a function to be called when the Deno worker process is terminated.

Type declaration

    • (code: number, signal: string): void
    • Parameters

      • code: number
      • signal: string

      Returns void

onmessage

onmessage: (e: MessageEvent) => void = null

Represents an event handler for the "message" event, that is a function to be called when a message is recieved from the worker.

Type declaration

Accessors

stderr

  • get stderr(): Readable

stdout

  • get stdout(): Readable

Methods

Private _handleTransferrables

Private _postMessage

  • _postMessage(channel: number | string | null, data: any, transfer?: Transferrable[]): void

addEventListener

  • Adds the given listener for the "message" event.

    Parameters

    • type: "message"

      The type of the event. (Always either "message" or "exit")

    • listener: OnMessageListener

      The listener to add for the event.

    Returns void

  • Adds the given listener for the "exit" event.

    Parameters

    • type: "exit"

      The type of the event. (Always either "message" or "exit")

    • listener: OnExitListener

      The listener to add for the event.

    Returns void

closeSocket

  • closeSocket(): void
  • Closes the websocket, which may allow the process to exit natually.

    Returns void

postMessage

  • Sends a message to the worker.

    Parameters

    • data: any

      The data to be sent. Copied via the Structured Clone algorithm so circular references are supported in addition to typed arrays.

    • Optional transfer: Transferrable[]

      Values that should be transferred. This should include any typed arrays that are referenced in the data.

    Returns void

removeEventListener

  • Removes the given listener for the "message" event.

    Parameters

    • type: "message"

      The type of the event. (Always either "message" or "exit")

    • listener: OnMessageListener

      The listener to remove for the event.

    Returns void

  • Removes the given listener for the "exit" event.

    Parameters

    • type: "exit"

      The type of the event. (Always either "message" or "exit")

    • listener: OnExitListener

      The listener to remove for the event.

    Returns void

terminate

  • terminate(): void

Generated using TypeDoc