BetaInvokes another function, of type durable or pubsub, and awaits its result. While awaiting, the durable function shuts down, so you are not charged for compute.
Step name
The value returned by the called function
// my-delegated-function/index.ts
export const handler = pubSubEventHandler(({event}) => {
return 'yo'
})
// my-resource/index.ts
export const handler = pubSubEventHandler(({event}) => {
return 'hey'
})
// my-durable-function/index.ts
export const handler = durableEventHandler(({step, context}) => {
// With a function name
const firstResult = await step.delegate({name: 'first-delegation', handler: 'my-delegated-function', event: {data: {hello: 'world'}}})
// With a resource object
const secondResult = await step.delegate({name: 'second-delegation', handler: context.resource.function('my-resource'), event: {data: {hello: 'world'}}})
})
Runs a set of steps, or branches, in parallel. Each branch contains its own child durable context, with all usual step operations available. Branches may be named.
Step name
A batch result of values returned or errors thrown by all branches.
const results: BatchResult<string> = await step.fanout<string>({
name: 'parallel-runs',
branches: [async ({step, logger}) => {
logger.log('Running first function in parallel')
return 'first'
}, {
func: async ({step, logger}) => {
logger.log('Running second function in parallel')
return 'second'
},
name: 'second-branch',
}],
})
Runs a set of steps, or branches, in parallel. Each branch contains its own child durable context, with all usual step operations available.
Step name
A batch result of values returned or errors thrown by all branches.
Runs a named step. Its result is recorded, so if the durable re-runs the step is not executed again. Failures are retried on their own.
Step name
The value returned by the provided handler
Waits for a specified duration
Step name
Resolves after the duration
Generates a unique callback ID, runs a submitter function to pass the ID to an external system and waits for some external system to POST JSON data to a Sanity Durable callback API using the callback ID.
try {
const successfulResult = await step.waitForCallback({name: 'ask-for-permission', submitter: async ({callbackId}) => {
await sendForApproval(callbackId)
}})
} catch (e) {
logger.log('oh no we received a callback failure', e)
}
@param name - Step name
@param submitter - Function that submits the provided callbackId parameter to an external system
@param timeout - Maximum time to wait for the callback result
@param retry - retry configuration for the submitter function
@returns The value returned to the Sanity Durable callback HTTP
Waits for a specified condition to be met by executing a poller method to retrieve state and then inspecting the retrieved state in a next method to determine whether to retry and after what delay to do so.
Step name
The value returned by the executed function
await step.waitForCondition({{
name: 'waitForCondition',
initial: {
article: null as Article | null,
},
poller: async (state, {attempt}) => {
const client = createClient({
apiVersion: '2026-08-05',
...context.clientOptions,
})
const article = await client.fetch<Article | null>(
'*[_type == "article"][0]',
)
return {...state, article}
},
next: (state, {attempt}) => {
if (state.article) return {shouldRetry: false}
return {
shouldRetry: true,
delay: {
seconds: Math.min(attempt * 2, 60),
},
}
},
},
)
The interface defining the durable operations available to a durable function. Using durables is considered experimental and may change in the future.