Move files to flipper-common
Summary: Moved Logger, sleep, timeout and server contract types to flipper-common packages. Reviewed By: passy Differential Revision: D31475790 fbshipit-source-id: 42d2147698875f9e919ad5250f9953f3bff3ec2d
This commit is contained in:
committed by
Facebook GitHub Bot
parent
cfd44b592a
commit
91d96774f6
14
desktop/flipper-common/src/utils/sleep.tsx
Normal file
14
desktop/flipper-common/src/utils/sleep.tsx
Normal file
@@ -0,0 +1,14 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
*/
|
||||
|
||||
export async function sleep(ms: number): Promise<void> {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(resolve, ms);
|
||||
});
|
||||
}
|
||||
24
desktop/flipper-common/src/utils/timeout.tsx
Normal file
24
desktop/flipper-common/src/utils/timeout.tsx
Normal file
@@ -0,0 +1,24 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
*/
|
||||
|
||||
import {sleep} from './sleep';
|
||||
|
||||
export function timeout<T>(
|
||||
ms: number,
|
||||
promise: Promise<T>,
|
||||
timeoutMessage?: string,
|
||||
): Promise<T> {
|
||||
// Create a promise that rejects in <ms> milliseconds
|
||||
const timeout = sleep(ms).then(() => {
|
||||
throw new Error(timeoutMessage || `Timed out in ${ms} ms.`);
|
||||
});
|
||||
|
||||
// Returns a race between our timeout and the passed in promise
|
||||
return Promise.race([promise, timeout]);
|
||||
}
|
||||
Reference in New Issue
Block a user