mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
a80674fc7c
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/43053 - Relocate under `scripts/e2e/` (also move util used only by this cript). - Type as Flow (to catch trivial errors). Some cleanup of `log()` calls as errors. Changelog: [Internal] Reviewed By: lunaleaps Differential Revision: D53813023 fbshipit-source-id: 05caf415ec0bf3739a6f7fec3afd385a195f42e9
39 lines
890 B
JavaScript
39 lines
890 B
JavaScript
/**
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @flow
|
|
* @format
|
|
* @oncall react_native
|
|
*/
|
|
|
|
/**
|
|
* Try executing a function n times recursively. Logs a warning message between
|
|
* each retry.
|
|
*/
|
|
function tryExecNTimes(
|
|
funcToRetry /*: () => number */,
|
|
retriesLeft /*: number */,
|
|
onEveryError /*: ?(() => mixed) */,
|
|
) /*: number */ {
|
|
const exitCode = funcToRetry();
|
|
if (exitCode === 0) {
|
|
return exitCode;
|
|
} else {
|
|
if (onEveryError) {
|
|
onEveryError();
|
|
}
|
|
retriesLeft--;
|
|
console.warn(`Command failed, ${retriesLeft} retries left`);
|
|
if (retriesLeft === 0) {
|
|
return exitCode;
|
|
} else {
|
|
return tryExecNTimes(funcToRetry, retriesLeft, onEveryError);
|
|
}
|
|
}
|
|
}
|
|
|
|
module.exports = tryExecNTimes;
|