Effection Logo

function main

thefrontside/effection

async function main(body: (args: string[]) => Operation<void>): Promise<void>

Top-level entry point to programs written in Effection. That means that your program should only call main once, and everything the program does is handled from within main including an orderly shutdown. Unlike run, main automatically prints errors that occurred to the console.

Use the https://effection-www-s5a0jkwj0z5x.deno.dev/api/v4/exit operation form within to halt program execution immediately and initiate shutdown.

The behavior of main is slightly different depending on the environment it is running in.

Deno, Node

When running within Deno or Node, any error which reaches main causes the entire process to exit with an exit code of 1.

Additionally, handlers for SIGINT are attached to the process, so that sending an exit signal to it causes the main task to become halted. This means that hitting CTRL-C on an Effection program using main will cause an orderly shutdown and run all cleanup code.

Warning! do not call Deno.exit() on Deno or process.exit() on Node directly, as this will not gracefully shutdown. Instead, use the https://effection-www-s5a0jkwj0z5x.deno.dev/api/v4/exit operation.

Browser

When running in a browser, The main operation gets shut down on the unload event.

Parameters

body: (args: string[]) => https://effection-www-s5a0jkwj0z5x.deno.dev/api/v4/Operation&lt;void>

  • an operation to run as the body of the program

Return Type

Promise<void>

a promise that resolves right after the program exits