624 B23 lines
Blame
1/**
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8// Compatibility utilities
9
10import {AbortController as AbortControllerCompat} from 'node-abort-controller';
11
12/**
13 * Like `new AbortController()` but works on older nodejs < 14.
14 */
15export function newAbortController(): AbortController {
16 if (typeof AbortController === 'function') {
17 // Prefer native AbortController.
18 return new AbortController();
19 } else {
20 return new AbortControllerCompat() as AbortController;
21 }
22}
23