Scoped promises for cancellation

30 views
Skip to first unread message

Sahand Evs

unread,
May 22, 2022, 10:38:19 PM5/22/22
to v8-users

Hi, Imagine the following code:

addEventListener("start", (user) => handler(user),);

async function handler(user) {
   await fetch();
   await fetch();
   await fetch()
          .then(x => fetch());
}

For this code, I want to have carried timeout. I have a 15 seconds time out of the budget at the start and each promise reduces this time when we reach zero we just throw an exception. This is trivial to implement if we are handling an event at a time. But I need to handle multiple events concurrently. I wondered if there is a way to create a scope per event that contains a start time and whenever a promise is polled or finished we check if the timeout is reached and if so, we reject all promises in the scope and throw an exception.

Thank you for your time reading this.

Reply all
Reply to author
Forward
0 new messages