Skip to main content
Module

x/kyuko/dev_deps.ts>DeployWorker

Fast and easy http framework for Deno Deploy 🦕
Latest
class DeployWorker
import { DeployWorker } from "https://deno.land/x/kyuko@v0.6.3/dev_deps.ts";

Constructors

new
DeployWorker(specifier: string | URL, unnamed 1?: DeployOptions)

Properties

readonly
logs: ReadableStream<string>

A readable stream the yields up log messages from the program.

Example:

const helloWorld = await createWorker("./helloWorld.ts");
// Use an async IIFE to avoid blocking the main loop
(async () => {
  for await (const msg of helloWorld.logs) {
    console.log(`[${helloWorld.name}] ${msg}`);
  }
})();
await helloWorld.listen({ port: 8000 });
readonly
name: string

The name of the worker.

readonly
ready: Promise<void>

A promise that resolves when the worker is initialized and ready.

readonly
state: DeployWorkerState

The current state of the worker.

Methods

check(options?: CheckOptions): Promise<Deno.Diagnostic[]>

Type check the program as if it were a Deploy script, resolving with an array of diagnostic information. If the array is empty, there were no issues with type checking.

close(): Promise<void>

Close and terminate the worker. The worker will resolve when any pending requests are settled.

fetch(
input: string | Request | URL,
requestInit?: RequestInit,
remoteAddr?: Deno.NetAddr,
): Promise<[Response, RequestResponseInfo]>

Send a request into the program and resolve with the resulting Response and additional information about the request.

For example:

const helloWorld = await createWorker("./hello_world.ts");
await helloWorld.run(async () => {
  const [response, info] = await helloWorld.fetch("/");
  // make assertions against the response
});
info(): Promise<DeployWorkerInfo>

Diagnostic information about the current worker.

listen(options: ListenOptions): Promise<void>

Start listening for requests, passing them to the worker and sending the responses back to the client.

Example:

const helloWorld = await createWorker("./helloWorld.ts");
await helloWorld.listen({ port: 8000 });
run<T>(callback: (this: this) => T | Promise<T>): Promise<T>

Start server and execute the callback. Once the callback finishes, the worker will be closed. Run resolves or rejects with the value returned from the callback. The callback will be called with the context of the worker.

This is useful when you need to run a set of assertions against the worker where the assertions might throw, but want to ensure the worker gets closed irrespective of if the callback throws or not.

Example:

const helloWorld = await createWorker("./helloWorld.ts");
await helloWorld.run(async function () {
  const [response, info] = await this.fetch("/");
  // make assertions against the response
});
start(): Promise<void>

Start the program, allowing it to take requests.

stop(): Promise<void>

Stop the program, preventing it from taking new requests. The program can be restarted.