@durable-effect/task is the lower-level package in the durable-effect ecosystem. It gives you direct access to the core primitives — task definitions, state management, scheduling, and the Cloudflare Durable Object integration — without the higher-level abstractions in @durable-effect/jobs.
When to use @durable-effect/task
Use @durable-effect/task when you need more control than @durable-effect/jobs provides:
- You want to bring your own Durable Object class and wiring
- You need to colocate multiple task types inside a single DO
- You’re building a custom runtime or test harness
- You need low-level access to storage or alarm primitives
@durable-effect/jobs instead.
Core concepts
Task.define(config) — defines a state machine. You provide schemas for state and events, then write onEvent and onAlarm handlers. The result is a TaskDefinition value that can be registered, tested, or wired into a Durable Object.
TaskContext<S> — the interface every handler receives. It provides typed access to state (recall, save, update), scheduling (scheduleIn, scheduleAt, cancelSchedule, nextAlarm), and lifecycle control (purge).
createTasks(definitions) — takes a record of task definitions and produces a ready-to-export Durable Object class (TasksDO) and a typed client accessor (tasks). This is the main entry point for Cloudflare deployments.
Package exports
The package has two entry points:| Import path | Purpose |
|---|---|
@durable-effect/task | Core definitions, schemas, testing utilities, service interfaces |
@durable-effect/task/cloudflare | Cloudflare-specific integration: createTasks, makeTaskEngine, storage and alarm adapters |
Install
@cloudflare/workers-types is an optional peer dependency — add it if you want full type checking for Cloudflare APIs.
Quick start
1. Define a task
2. Export the Durable Object
3. Configure wrangler
4. Send events and read state
Defining tasks
Task.define() config, TaskContext API, service dependencies, and multiple tasks per DO
Testing
In-memory storage and alarm, test stack setup, and complete test examples
