Course lesson 37 · Managing Workflows with Durable Objects

Building the Base Class

One study unit · Read, recall, then practice · Original video 00:13:44

The instructor builds a small persistent counter inside the future evaluation-scheduler class to make Durable Object identity and state tangible. The constructor restores stored state under blockConcurrencyWhile, methods update and return the count, and a temporary HTTP route calls those methods through a stub. Calling the route with two names demonstrates two independent objects whose values remain separate.

Primary source: course video 37 · Supplied English subtitles · 00:13:44.

Understand the idea

What the course does

  1. Create the evaluation-scheduler class, call the base constructor, and initialise a count field.
  2. Restore count from storage under blockConcurrencyWhile, defaulting when no value exists.
  3. Implement increment with a storage write and get-count with an in-memory read.
  4. Configure the Durable Object binding and the initial migration for the course’s key-value-backed class.
  5. Export the class, regenerate environment types, and add a temporary route that selects an object by name.
  6. Run locally and alternate between two names, observing independent counters and retained values when returning to each name.

Watch for

Recall before revealing

Why do test-one and test-two keep separate counts even though they use the same class?

Reveal the explanation

The namespace resolves their different names to different object instances, and each instance owns its own state.

Try it

Reproduce the two-name counter experiment, then stop and restart the local service without deleting its persistent state and check the counts again.

Check your result

You can distinguish separate object identities from separate in-memory lifetimes and explain how storage restores each value.

Practice prompts and answer checks are added teaching material. Answer from memory first, then compare and explain any difference.

Rewatch only what you need

Open this lesson in your original course library and seek to the times below. Videos are not hosted on this site.

Companion primary documentation: What are Durable Objects?. For recorded API names, commands, limits, and prices, check the version you use.

← Previous   Next →