One sleep to rule them all. Zzz

Summary: Boyscouted some code duplication away.

Reviewed By: jknoxville

Differential Revision: D29731016

fbshipit-source-id: d5f1677a667f032f6e7e031da296be26e1976932
This commit is contained in:
Michel Weststrate
2021-07-16 03:42:14 -07:00
committed by Facebook GitHub Bot
parent d23ccfcd44
commit 57d00e0bab
8 changed files with 7 additions and 31 deletions

View File

@@ -9,8 +9,8 @@
import {Notification} from 'flipper-plugin';
import {Actions} from './';
import {getStringFromErrorLike} from '../utils';
import React from 'react';
import {getStringFromErrorLike} from '../utils/errors';
export const GLOBAL_NOTIFICATION_PLUGIN_ID = 'Flipper';

View File

@@ -15,7 +15,7 @@ import {LaunchEmulatorDialog} from '../LaunchEmulator';
import {createRootReducer} from '../../../reducers';
import {act} from 'react-dom/test-utils';
import {sleep} from '../../../utils';
import {sleep} from 'flipper-plugin';
jest.mock('../../../devices/AndroidDevice', () => ({
launchEmulator: jest.fn(() => Promise.resolve([])),

View File

@@ -8,8 +8,7 @@
*/
import {CancelledPromiseError} from './errors';
import {sleep} from './promiseTimeout';
import {Idler} from 'flipper-plugin';
import {Idler, sleep} from 'flipper-plugin';
export class IdlerImpl implements Idler {
private lastIdle = performance.now();

View File

@@ -8,7 +8,7 @@
*/
import {IdlerImpl, TestIdler} from '../Idler';
import {sleep} from '../promiseTimeout';
import {sleep} from 'flipper-plugin';
test('Idler should interrupt', async () => {
const idler = new IdlerImpl();

View File

@@ -10,7 +10,7 @@
import {sideEffect} from '../sideEffect';
import {createStore, Store} from 'redux';
import produce from 'immer';
import {sleep} from '../promiseTimeout';
import {sleep} from 'flipper-plugin';
jest.useFakeTimers();

View File

@@ -1,11 +0,0 @@
/**
* 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 {getStringFromErrorLike} from './errors';
export {sleep} from './promiseTimeout';

View File

@@ -7,6 +7,7 @@
* @format
*/
import {sleep} from 'flipper-plugin';
import {StatusMessageType} from '../reducers/application';
export default function promiseTimeout<T>(
@@ -23,15 +24,6 @@ export default function promiseTimeout<T>(
return Promise.race([promise, timeout]);
}
export function sleep(ms: number): Promise<void> {
return new Promise((resolve) => {
const id = setTimeout(() => {
clearTimeout(id);
resolve();
}, ms);
});
}
export function showStatusUpdatesForPromise<T>(
promise: Promise<T>,
message: string,

View File

@@ -7,13 +7,9 @@
* @format
*/
import {TestUtils} from 'flipper-plugin';
import {TestUtils, sleep} from 'flipper-plugin';
import * as plugin from '..';
async function sleep(ms: number) {
return new Promise<void>((resolve) => setTimeout(() => resolve(), ms));
}
// this testing is inspired by Flipper sample app
test('general plugin logic testing', async () => {
const {instance, onSend, connect, sendEvent} = TestUtils.startPlugin(plugin, {