Why is waitUntil not working in my Vercel serverless function?

Hi everyone,

I’m trying to execute a series of asynchronous tasks in a Vercel serverless function using waitUntil. However, it doesn’t seem to work as expected, and my function times out with the following
error: Vercel Runtime Timeout Error: Task timed out after 15 seconds

It sounds like you might be hitting the default max duration for a serverless function. Have you tried increasing it? Configuring Maximum Duration for Vercel Functions

1 Like

Thanks for jumping in here, @dev-adclear! Definitely extra points for the leaderboard if you’re interested :smiley:

@johnson-8844 Let us know how you get on!

1 Like

I couldn’t predict the duration of the API call, so I used the waitUntil function. It was working fine initially, but suddenly, it stopped working. Why could this be happening?

Code

Hi @johnson-8844, waitUntil should work fine but remember it doesn’t make your function run more than the maximum time limit.

From the code, I’d recommend doing parallel calls instead of sequential:

const tasks = async () => {
        await Promise.all([countVotes(),
        createBattle(),
        mintNfts(),
        automateReward()]
      };

This should reduce the total execution time but you should still check what is slowing your function down.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.