Skip to main content
this.ctx (an ActorContext) holds the instance’s identity, per-key storage, single alarm, and one-shot init.
interface ActorContext {
  readonly id: string;             // the name you chose with idFromName(name)
  readonly storage: ActorStorage;  // see Actor Storage
  blockConcurrencyWhile<T>(fn: () => Promise<T>): Promise<T>;
  setAlarm(when: number): Promise<void>;  // alias for ctx.storage.setAlarm(when)
}

ctx.id

The customer-supplied name for this actor — opaque string. You chose it via env.<BINDING>.idFromName(name). Common patterns: caller E.164, CRM user id, email, or a composite key.

ctx.blockConcurrencyWhile(fn)

One-shot init primitive. Use it inside a subclass constructor to gate all other calls until init finishes. 30s budget — a callback that exceeds it fails init (BlockConcurrencyTimeoutError), and the activation is torn down and retried on the next call.
class MyActor extends StatefulActor<Env> {
  constructor(ctx: ActorContext, env: Env) {
    super(ctx, env);
    ctx.blockConcurrencyWhile(async () => {
      // preload state, set up initial alarm, etc.
      // every other method call to this instance waits until this resolves
    });
  }
}

ctx.setAlarm(when)

Top-level alias for ctx.storage.setAlarm(when). when is ms since epoch. See Alarms.