---
description: You can now import `waitUntil` from `cloudflare:workers` to extend execution of background tasks without requiring the request context
title: Directly import `waitUntil` in Workers for easily spawning background tasks
image: https://developers.cloudflare.com/changelog/post/2025-08-08-add-waituntil-cloudflare-workers/og.png?v=00396226f3a4c049
---

[Skip to content](#main-content)

[View RSS feeds](https://developers.cloudflare.com/fundamentals/new-features/available-rss-feeds/) [ Subscribe to RSS](https://developers.cloudflare.com/changelog/rss/index.xml)

[Back to all posts](https://developers.cloudflare.com/changelog)

August 8, 2025

## Directly import \`waitUntil\` in Workers for easily spawning background tasks

[Workers](https://developers.cloudflare.com/workers/)

Copy as Markdown| [View as Markdown](https://developers.cloudflare.com/changelog/post/2025-08-08-add-waituntil-cloudflare-workers/index.md)| [Agent setup](https://developers.cloudflare.com/agent-setup/)

You can now import [`waitUntil`](https://developers.cloudflare.com/workers/runtime-apis/context/#waituntil) from `cloudflare:workers` to extend your Worker's execution beyond the request lifecycle from anywhere in your code.

Previously, `waitUntil` could only be accessed through the [execution context](https://developers.cloudflare.com/workers/runtime-apis/context/) (`ctx`) parameter passed to your Worker's handler functions. This meant that if you needed to schedule background tasks from deeply nested functions or utility modules, you had to pass the `ctx` object through multiple function calls to access `waitUntil`.

Now, you can import `waitUntil` directly and use it anywhere in your Worker without needing to pass `ctx` as a parameter:

```js
import { waitUntil } from "cloudflare:workers";

export function trackAnalytics(eventData) {
	const analyticsPromise = fetch("https://analytics.example.com/track", {
		method: "POST",
		body: JSON.stringify(eventData),
	});

	// Extend execution to ensure analytics tracking completes
	waitUntil(analyticsPromise);
}
```

This is particularly useful when you want to:

- Schedule background tasks from utility functions or modules
- Extend execution for analytics, logging, or cleanup operations
- Avoid passing the execution context through multiple layers of function calls

```js
import { waitUntil } from "cloudflare:workers";

export default {
	async fetch(request, env, ctx) {
		// Background task that should complete even after response is sent
		cleanupTempData(env.KV_NAMESPACE);
		return new Response("Hello, World!");
	}
};

function cleanupTempData(kvNamespace) {
	// This function can now use waitUntil without needing ctx
	const deletePromise = kvNamespace.delete("temp-key");
	waitUntil(deletePromise);
}
```

Note

The imported `waitUntil` function works the same way as [`ctx.waitUntil()`](https://developers.cloudflare.com/workers/runtime-apis/context/#waituntil). It extends your Worker's execution to wait for the provided promise to settle, but does not block the response from being sent to the client.

For more information, see the [`waitUntil` documentation](https://developers.cloudflare.com/workers/runtime-apis/context/#waituntil).

```json
{"@context":"https://schema.org","@type":"BlogPosting","@id":"https://developers.cloudflare.com/changelog/post/2025-08-08-add-waituntil-cloudflare-workers/#page","headline":"Directly import `waitUntil` in Workers for easily spawning background tasks","description":"You can now import waitUntil from cloudflare:workers to extend execution of background tasks without requiring the request context","url":"https://developers.cloudflare.com/changelog/post/2025-08-08-add-waituntil-cloudflare-workers/","inLanguage":"en","image":"https://developers.cloudflare.com/changelog/post/2025-08-08-add-waituntil-cloudflare-workers/og.png?v=00396226f3a4c049","dateModified":"2025-08-08","datePublished":"2025-08-08","publisher":{"@type":"Organization","name":"Cloudflare","description":"One platform for your apps, agents, and workforce. Build, secure, and scale without managing infrastructure","url":"https://www.cloudflare.com/","sameAs":["https://github.com/cloudflare","https://www.linkedin.com/company/cloudflare","https://x.com/cloudflare"],"logo":{"@type":"ImageObject","url":"https://developers.cloudflare.com/logo.svg"},"address":{"@type":"PostalAddress","streetAddress":"101 Townsend St","addressLocality":"San Francisco","addressRegion":"CA","postalCode":"94107","addressCountry":"US"},"contactPoint":[{"@type":"ContactPoint","contactType":"Customer Support","url":"https://support.cloudflare.com/","availableLanguage":["English"]},{"@type":"ContactPoint","contactType":"Sales","url":"https://www.cloudflare.com/contact/","availableLanguage":["English"]}]},"isPartOf":{"@type":"WebSite","@id":"https://developers.cloudflare.com/#website","name":"Cloudflare Docs","url":"https://developers.cloudflare.com/"}}
```
