Skip to main content

Built and signed on GitHub Actions

Structured Concurrency and Effects for JavaScript

This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score
100%
Published
3 weeks ago (3.1.0)
f
action

Create an Operation that can be either resolved (or rejected) with a synchronous callback. This is the Effection equivalent of new Promise().

f
all

Block and wait for all of the given operations to complete. Returns an array of values that the given operations evaluated to. This has the same purpose as Promise.all.

f
call

Pause the current operation, then run an async function, or operation function in a new scope. The calling operation will be resumed (or errored) once call is completed.

T
Callable

A uniform integration type representing anything that can be evaluated as a the parameter to call.

I
Channel

A broadcast channel that multiple consumers can subscribe to the via the same Stream, and messages sent to the channel are received by all consumers. The channel is not buffered, so if there are no consumers, the message is dropped.

I
Context

`Context`` defines a value which is in effect for a given scope which is an (action, resource, call, or spawn).

f
createChannel

Create a new Channel. Use channels to communicate between operations. In order to dispatch messages from outside an operation such as from a callback, use Signal.

f
createContext
No documentation available
f
createQueue

Creates a new queue. Queues are unlimited in size and sending a message to a queue is always synchronous.

f
createScope

Create a new scope to serve as an entry point from normal JavaScript execution into Effection.

f
createSignal

Create a new Signal

f
N
each

Consume an effection stream using a simple for-of loop.

v
each.next
No documentation available
f
ensure

Run the given function or operation when the current operation shuts down. This is equivalent to running the function or operation in a finally {} block, but it can help you avoid rightward drift.

f
exit

Halt process execution immediately and initiate shutdown. If a message is provided, it will be logged to the console after shutdown:

I
Future

A value that is both an Operation and Promise.

f
lift

Convert a simple function into an Operation

f
main

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.

f
on

Create a Stream of events from any EventTarget.

f
once

Create an Operation that yields the next event to be emitted by an EventTarget.

I
Operation

An Operation in Effection describes an abstract computation. An operation does not do anything on its own. Rather, it only describes the steps it will take when it runs.

T
Provide
No documentation available
I
Queue

A FIFO queue which can be used to implement the Subscription interface directly. Most of the time, you will use either a Signal or a Channel as the mechanism, but Queue allows you to manage a single subscription directly.

f
race

Race the given operations against each other and return the value of whichever operation returns first. This has the same purpose as Promise.race.

T
Reject
No documentation available
T
Resolve
No documentation available
f
resource

Define an Effection resource

f
run

Execute an operation.

I
Scope

A programatic API to interact with an Effection scope from outside of an Operation.

I
Signal

Convert plain JavaScript function calls into a Stream that can be consumed within an operation. If no operation is subscribed to a signal's stream, then sending messages to it is a no-op.

f
sleep

Sleep for the given amount of milliseconds.

f
spawn

Run another operation concurrently as a child of the current one.

T
Stream

The Effection equivalent of an AsyncIterable.

f
stream

Convert any AsyncIterable into an Effection Stream.

f
subscribe

Convert any AsyncIterator into an effection Subscription

I
Subscription

The Effection equivalent of an AsyncIterator

f
suspend

Indefinitely pause execution of the current operation. It is typically used in conjunction with an action to mark the boundary between setup and teardown.

I
Task

A handle to a concurrently running operation that lets you either use the result of that operation, or shut it down.

f
useAbortSignal

Create an AbortSignal bound to the current scope. Whenever that scope is completed, errored, or halted, the abort signal will be triggered.

f
useScope

Get the scope of the currently running Operation.

T
Yielded

Unwrap the type of an Operation. Analogous to the built in Awaited type. Yielded<Operation> === T