Persistent Sleep
Persistent or durable sleep means the workflow's state is saved, and execution will resume after the
duration has elapsed, even if the Obelisk server restarts. Workflows use obelisk.sleep instead of
setTimeout:
import * as obelisk from "obelisk:workflow@1.0.0";
obelisk.sleep({ seconds: 10 });
obelisk.sleep(new Date(Date.now() + 30_000)); // absolute wake-up time
const wokeAt = obelisk.sleep({ days: 1 }, "reminder"); // optional name, returns a Date
sleep creates a one-off join set
with a delay and blocks until the delay expires. The optional second argument names that join set.
If the durable sleep is cancelled, sleep throws obelisk.ChildError with cancelled === true.
See Cancellation for
how delay cancellation fits into structured concurrency.
Delays in a join set
A delay can also be submitted to a join set next to child executions. This is how a workflow
implements a timeout: whichever finishes first is returned by joinNext, and closing the join set
cancels the rest.
import * as obelisk from "obelisk:workflow@1.0.0";
import * as dynamic from "obelisk:workflow-dynamic@1.0.0";
const js = obelisk.createJoinSet();
const execId = dynamic.submit(js, "myapp:demo/activity.step", [1, 200]);
const delayId = js.submitDelay({ seconds: 10 });
const result = js.joinNext(); // null if the delay won
if (js.lastId === delayId) {
return "timed out";
}
See Heterogenous Join Sets. For Rust, see Rust Workflows.