Menu

Workflow SDK now supports inflight cancellation - Vercel
📰

Workflow SDK now supports inflight cancellation - Vercel

Vercel News·Pranay Prakash·5 days ago
#CWRViE5f
Reading 0:00
15s threshold

The Workflow SDK 5 beta now supports the standard AbortController and AbortSignal APIs across workflow and step boundaries.

Create a controller inside a workflow, pass its signal into one or more steps, and cancel in-flight operations using the same API fetch already uses.

import { sleep } from "workflow" ;

export async function cancellableWorkflow ( ) {

"use workflow" ;

const controller = new AbortController ( ) ;

const result = await Promise . race ( [

fetchReport ( controller . signal ) ,

sleep ( "30s" ) . then ( ( ) => null ) ,

] ) ;

if ( result === null ) {

controller . abort ( ) ;

return { status : "timed-out" } ;

}

return result ;

}

async function fetchReport ( signal : AbortSignal ) {

"use step" ;

const response = await fetch ( "https://api.example.com/report" , {

signal ,

} ) ;

return response . json ( ) ;

}

Passing a signal into a step and cancelling the in-flight operation

That signal stays durable across suspensions and deterministic replay.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.