sindresorhus / p-race

A better `Promise.race()`

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Also cancel remaining promises

fregante opened this issue · comments

It kind of irks me that the default for races is to just let everything continue even when the race ended.

What do you think about also calling .cancel to the promises that are running?

I'm not sure I want to continue adding support for the p-cancelable way. It seems the ecosystem is moving to use AbortController. Is there any way we could support AbortController for this?

I suppose that the 2 could actually just be combined here, without extending p-cancelable

new pRace([
	signal => fetch('/api', {signal}),
	signal => setTimeout(10, {signal}),
])

Or

new pRace(signal => [
	fetch('/api', {signal}),
	setTimeout(10, {signal}),
])

Also shortcuttable to:

new pRace([
	[fetch, '/api'],
	[setTimeout, 10],
])

But this has a few drawbacks and some errors would be silent

new pRace(signal => [
fetch('/api', {signal}),
setTimeout(10, {signal}),
])

I like this one.