Deprecated
preventSleep
Replace the deprecated preventSleep and setPreventSleep with keepAwake and waitUntil.
preventSleep and setPreventSleep were deprecated in 3.0 and will be removed in a future version. They are no-ops: setPreventSleep does nothing and preventSleep always returns false.
What is deprecated
c.setPreventSleep(enabled)andc.preventSleepin TypeScript.Ctx::set_prevent_sleepandCtx::prevent_sleepin Rust.
import { actor } from "rivetkit";
// An actor that still uses the deprecated `setPreventSleep`
const uploader = actor({
actions: {
upload: async (c, url: string) => {
c.setPreventSleep(true);
try {
await fetch(url, { method: "POST" });
} finally {
c.setPreventSleep(false);
}
},
},
});
Because these calls no longer do anything, an actor that relies on them can sleep in the middle of the work they were meant to protect.
Use keepAwake or waitUntil
Scope the work that must finish to a promise instead of toggling a flag:
c.keepAwake(promise)blocks sleep until the promise settles and returns its result. Use it when the caller waits for the work.c.waitUntil(promise)lets the current request return right away and finishes the promise before the actor sleeps. Use it for background work.
import { actor } from "rivetkit";
const uploader = actor({
actions: {
// `keepAwake` blocks sleep until the promise settles and returns its result
upload: async (c, url: string) => {
const response = await c.keepAwake(fetch(url, { method: "POST" }));
return response.status;
},
// `waitUntil` lets the action return now and finishes the work in the
// background before the actor sleeps
uploadInBackground: (c, url: string) => {
c.waitUntil(fetch(url, { method: "POST" }));
},
},
});
In Rust, use Ctx::keep_awake and Ctx::wait_until. See Lifecycle for how sleep works.