Skip to content

Commit 8de2367

Browse files
committed
feat(compute): rename keep awake guard
1 parent 9b64d1a commit 8de2367

4 files changed

Lines changed: 25 additions & 25 deletions

File tree

packages/compute/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,27 @@ import { waitUntil } from "@prisma/compute";
1919
waitUntil(doCriticalWork(), { signal: AbortSignal.timeout(30_000) });
2020
```
2121

22-
`ScaleToZeroGuard` is a disposable object that keeps the application awake until the guard is released. Use it for a scoped function or block of background work. `ScaleToZeroGuard` can be created multiple times during a single request and is safe to nest. Pass an `AbortSignal`, usually from `AbortSignal.timeout(ms)`, as a safety bound if release is not reached. The signal releases the guard only; it does not cancel the guarded work.
22+
`KeepAwakeGuard` is a disposable object that keeps the application awake until the guard is released. Use it for a scoped function or block of background work. `KeepAwakeGuard` can be created multiple times during a single request and is safe to nest. Pass an `AbortSignal`, usually from `AbortSignal.timeout(ms)`, as a safety bound if release is not reached. The signal releases the guard only; it does not cancel the guarded work.
2323

2424
Read more about disposables and the `using` keyword in the [MDN resource management guide](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Resource_management).
2525

2626
```ts
27-
import { ScaleToZeroGuard } from "@prisma/compute";
27+
import { KeepAwakeGuard } from "@prisma/compute";
2828

2929
async function runsInBackground() {
3030
// guard is acquired here
31-
using guard = new ScaleToZeroGuard({ signal: AbortSignal.timeout(30_000) });
31+
using guard = new KeepAwakeGuard({ signal: AbortSignal.timeout(30_000) });
3232
await doCriticalWork();
3333
} // guard is released here
3434
```
3535

3636
If `using` is not available, call `.release()` manually. Always release the guard in a `finally` block so it is released even if the guarded code throws.
3737

3838
```ts
39-
import { ScaleToZeroGuard } from "@prisma/compute";
39+
import { KeepAwakeGuard } from "@prisma/compute";
4040

4141
async function runsInBackground() {
42-
const guard = new ScaleToZeroGuard({ signal: AbortSignal.timeout(30_000) });
42+
const guard = new KeepAwakeGuard({ signal: AbortSignal.timeout(30_000) });
4343

4444
try {
4545
await doCriticalWork();

packages/compute/src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// biome-ignore lint/performance/noBarrelFile: Package entrypoint intentionally re-exports the public API.
22
export {
3-
ScaleToZeroGuard,
4-
type ScaleToZeroGuardOptions,
3+
KeepAwakeGuard,
4+
type KeepAwakeGuardOptions,
55
waitUntil,
6-
} from "./scale-to-zero";
6+
} from "./keep-awake-guard";
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { writeScaleToZeroSignal } from "./scale-to-zero-control";
33
/**
44
* Options for holding a Prisma Compute sleep guard.
55
*/
6-
export interface ScaleToZeroGuardOptions {
6+
export interface KeepAwakeGuardOptions {
77
/**
88
* Signal that releases the keep-awake guard when aborted.
99
*
@@ -19,7 +19,7 @@ export interface ScaleToZeroGuardOptions {
1919
* Keeps a Prisma Compute application awake for scoped async work.
2020
*
2121
* Creating a guard signals the compute runtime to stay awake. Calling
22-
* {@link ScaleToZeroGuard.release}, leaving a `using` scope, or reaching
22+
* {@link KeepAwakeGuard.release}, leaving a `using` scope, or reaching
2323
* the configured abort signal releases that signal. Release is idempotent, so
2424
* manual release and disposal can be combined safely.
2525
*
@@ -32,23 +32,23 @@ export interface ScaleToZeroGuardOptions {
3232
*
3333
* @example
3434
* ```ts
35-
* import { ScaleToZeroGuard } from "@prisma/compute";
35+
* import { KeepAwakeGuard } from "@prisma/compute";
3636
*
37-
* using guard = new ScaleToZeroGuard({ signal: AbortSignal.timeout(30_000) });
37+
* using guard = new KeepAwakeGuard({ signal: AbortSignal.timeout(30_000) });
3838
* await doCriticalWork();
3939
* ```
4040
*
4141
* @example
4242
* ```ts
43-
* const guard = new ScaleToZeroGuard();
43+
* const guard = new KeepAwakeGuard();
4444
* try {
4545
* await doCriticalWork();
4646
* } finally {
4747
* guard.release();
4848
* }
4949
* ```
5050
*/
51-
export class ScaleToZeroGuard implements Disposable {
51+
export class KeepAwakeGuard implements Disposable {
5252
#active: boolean;
5353
#abortSignal: AbortSignal | undefined;
5454
#abortListener: (() => void) | undefined;
@@ -61,7 +61,7 @@ export class ScaleToZeroGuard implements Disposable {
6161
* guarded work. Passing a signal is recommended as a safety bound if release
6262
* is not reached.
6363
*/
64-
constructor(options: ScaleToZeroGuardOptions = {}) {
64+
constructor(options: KeepAwakeGuardOptions = {}) {
6565
if (options.signal?.aborted) {
6666
this.#active = false;
6767
return;
@@ -100,7 +100,7 @@ export class ScaleToZeroGuard implements Disposable {
100100
* Releases the guard when used with TypeScript's `using` syntax.
101101
*
102102
* Most callers should prefer `using` for scoped work and call
103-
* {@link ScaleToZeroGuard.release} only when release needs to happen before
103+
* {@link KeepAwakeGuard.release} only when release needs to happen before
104104
* the scope exits.
105105
*/
106106
[Symbol.dispose](): void {
@@ -140,10 +140,10 @@ export class ScaleToZeroGuard implements Disposable {
140140
*/
141141
export function waitUntil(
142142
promise: PromiseLike<unknown>,
143-
options?: ScaleToZeroGuardOptions,
143+
options?: KeepAwakeGuardOptions,
144144
): void {
145145
// biome-ignore lint/nursery/useDisposables: waitUntil transfers guard cleanup to the promise finally handler.
146-
const guard = new ScaleToZeroGuard(options);
146+
const guard = new KeepAwakeGuard(options);
147147

148148
// Do not attach a catch here; callers rely on the underlying promise keeping
149149
// its normal unhandled-rejection behavior.

packages/compute/tests/scale-to-zero.test.ts renamed to packages/compute/tests/keep-awake-guard.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import path from "node:path";
44

55
import { afterEach, describe, expect, it, vi } from "vitest";
66

7-
import { ScaleToZeroGuard, waitUntil } from "../src/index";
7+
import { KeepAwakeGuard, waitUntil } from "../src/index";
88
import { configureScaleToZeroControlFileForTests } from "../src/scale-to-zero-control";
99

1010
async function createControlFile(): Promise<{ dir: string; file: string }> {
@@ -20,7 +20,7 @@ async function readSignals(file: string): Promise<string> {
2020
return await fs.readFile(file, "utf8");
2121
}
2222

23-
describe("scale-to-zero guard", () => {
23+
describe("keep-awake guard", () => {
2424
afterEach(async () => {
2525
vi.useRealTimers();
2626
configureScaleToZeroControlFileForTests(undefined);
@@ -29,7 +29,7 @@ describe("scale-to-zero guard", () => {
2929
it("writes acquire and release signals for a disposable guard", async () => {
3030
const { file } = await createControlFile();
3131

32-
using guard = new ScaleToZeroGuard();
32+
using guard = new KeepAwakeGuard();
3333

3434
expect(await readSignals(file)).toBe("+");
3535
guard.release();
@@ -38,7 +38,7 @@ describe("scale-to-zero guard", () => {
3838

3939
it("releases only once when release is called multiple times", async () => {
4040
const { file } = await createControlFile();
41-
using guard = new ScaleToZeroGuard();
41+
using guard = new KeepAwakeGuard();
4242

4343
guard.release();
4444
guard.release();
@@ -51,7 +51,7 @@ describe("scale-to-zero guard", () => {
5151
const { file } = await createControlFile();
5252
const controller = new AbortController();
5353

54-
using guard = new ScaleToZeroGuard({ signal: controller.signal });
54+
using guard = new KeepAwakeGuard({ signal: controller.signal });
5555
expect(await readSignals(file)).toBe("+");
5656

5757
controller.abort();
@@ -66,7 +66,7 @@ describe("scale-to-zero guard", () => {
6666
const controller = new AbortController();
6767
controller.abort();
6868

69-
using guard = new ScaleToZeroGuard({ signal: controller.signal });
69+
using guard = new KeepAwakeGuard({ signal: controller.signal });
7070
guard.release();
7171

7272
expect(await readSignals(file)).toBe("");
@@ -119,7 +119,7 @@ describe("scale-to-zero guard", () => {
119119
it("removes the abort listener after manual release", async () => {
120120
const { file } = await createControlFile();
121121
const controller = new AbortController();
122-
using guard = new ScaleToZeroGuard({ signal: controller.signal });
122+
using guard = new KeepAwakeGuard({ signal: controller.signal });
123123

124124
guard.release();
125125
controller.abort();

0 commit comments

Comments
 (0)