Move devices to server folder
Summary: This is the first of many diffs that extracts the connection, device, client detection out of the flipper core, to create a reusable flipper-server library that can be used in e.g. flipper-dump. To keep diffs a little smaller, the current connection logic is first moved to the `server/` directory, and decoupled manually from the rest of the core, before moving it over to a separate package. This first diffs moves the `comms/`, `devices/` and certificate utilities to the `server` directory. Further untangling will follow in next diffs Reviewed By: timur-valiev Differential Revision: D30246551 fbshipit-source-id: c84259bfb1239119b3267a51b015e30c3c080866
This commit is contained in:
committed by
Facebook GitHub Bot
parent
5e350add4f
commit
5e8c968222
24
desktop/flipper-plugin/src/utils/timeout.tsx
Normal file
24
desktop/flipper-plugin/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