> ## Documentation Index
> Fetch the complete documentation index at: https://bunnynet-cb9733c2-add-new-partner-apis.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Runtime

> The runtime APIs available on the bunny.net platform.

The bunny.net EdgeScript Runtime is based on Deno, so you can use a subset of
what is available from Deno or Node. On top of that, we provide functions that
change how the script behaves in our environment or bind it to other bunny.net
services.

## waitUntil

The `waitUntil` function extends the life of the isolate running a request. Use
it when a script needs to keep working after the request it answered has
finished. Even when no other requests are routed to the script, the invocation
stays alive.

It is useful for holding [WebSocket](./websockets) connections open, refreshing
a cache entry in the background, or firing off telemetry once the response has
gone back to the client.

### Signature

```typescript theme={null}
Bunny.v1.waitUntil(promise: Promise<unknown>): void;
```

### Parameters

<ParamField body="promise" type="Promise<unknown>" required>
  A promise representing background work. The isolate will stay alive until
  this promise settles (resolves or rejects).
</ParamField>

### Returns

`void`. `waitUntil` does not return a value.

<Note>
  You can call `waitUntil` multiple times; the script will only be evicted once
  every given promise has been resolved.
</Note>

### Example

Return the response to the client immediately while a slower task, in this case
populating the cache, finishes in the background.

```typescript theme={null}
import * as BunnySDK from "@bunny.net/edgescript-sdk";

BunnySDK.net.http.serve(async (request: Request): Promise<Response> => {
  const url = new URL(request.url);
  const cache = caches.default;
  const cacheKey = new Request(url.toString(), { method: "GET" });

  const hit = await cache.match(cacheKey);
  if (hit) {
    return hit;
  }

  const fresh = Response.json(
    { generatedAt: new Date().toISOString(), random: Math.random() },
    { headers: { "Cache-Control": "s-maxage=60" } },
  );

  // Don't block the response on the cache write. Let it finish after we
  // return; the isolate stays alive until cache.put() resolves.
  Bunny.v1.waitUntil(cache.put(cacheKey, fresh.clone()));

  return fresh;
});
```

## References

* [WebSocket](./websockets)
* [Cache API](./cache)
