Skip to content

Conversation

@retyui
Copy link
Contributor

@retyui retyui commented Jan 21, 2026

Summary:

Fix issue: #55247

I'm ok to continue to use abort-controller package (even if it isn't maintainable for 8 years) but to have modern API, I believe we can add polifils on the React Native side

Changelog:

[GENERAL] [ADDED] - Added support for AbortSignal.any(signals), AbortSignal.timeout(time) and AbortSignal::reason

Test Plan:

fetch('https://www.google.com', { signal: AbortSignal.timeout(0) }).catch(e => {
  console.log(e); // AbortError: Aborted
})

AbortSignal.timeout(-1); // error 
AbortSignal.timeout();  // error
AbortSignal.timeout({}); // error
AbortSignal.timeout(NaN); // error

const signal = AbortSignal.timeout(0);
// wait for a sec. and check:
console.log(signal.aborted); // true
console.log(signal.reason); // TimeoutError: signal timed out

// --------------------------------------------

AbortSignal.any(); // error
AbortSignal.any(''); // error
AbortSignal.any([  // error
  new AbortController().signal,
  "not signal val"
]); 

const controllers = [new AbortController(), new AbortController()];
const signal2 = AbortSignal.any([controllers[0].signal, controllers[1].signal]);

const index = Math.floor(Math.random() * 2);
controllers[index].abort();

console.log(signal2.aborted);  // true.
console.log(signal2.reason);  // AbortError: The operation was aborted

const signal3 = AbortSignal.any([]);
console.log(signal3.aborted);  // Always false.

// --------------------------------------------
// Jest env. will use Node.js impl.

test('jest env', async () => {
  const signal = AbortSignal.timeout(0);

  expect(signal.aborted).toBe(false);
  expect(signal.reason).toBeUndefined();

  await new Promise(ok => setTimeout(ok, 100));

  expect(signal.aborted).toBe(true);
  expect(signal.reason).toBeInstanceOf(DOMException);
});

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jan 21, 2026
@retyui retyui force-pushed the feat/retyui/AbortSignal branch from 0a9875c to cb5adc1 Compare January 21, 2026 21:56
@facebook-github-bot facebook-github-bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Jan 21, 2026
@retyui retyui force-pushed the feat/retyui/AbortSignal branch from cb5adc1 to 6d38ebd Compare January 21, 2026 22:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. p: Callstack Partner: Callstack Partner Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants