From 0f6e3e3727c2c8dcb200feebbe4b8e80c9f36caf Mon Sep 17 00:00:00 2001 From: Gareth Jones Date: Sun, 18 Feb 2024 10:41:18 +1300 Subject: [PATCH] refactor: inline `tick` and `until` functions --- src/fsa-to-node/__tests__/FsaNodeFs.test.ts | 11 ++++++++++- src/thingies/index.ts | 2 -- src/thingies/tick.ts | 1 - src/thingies/until.ts | 8 -------- 4 files changed, 10 insertions(+), 12 deletions(-) delete mode 100644 src/thingies/tick.ts delete mode 100644 src/thingies/until.ts diff --git a/src/fsa-to-node/__tests__/FsaNodeFs.test.ts b/src/fsa-to-node/__tests__/FsaNodeFs.test.ts index 29f1632ee..e21524b1b 100644 --- a/src/fsa-to-node/__tests__/FsaNodeFs.test.ts +++ b/src/fsa-to-node/__tests__/FsaNodeFs.test.ts @@ -3,10 +3,19 @@ import { AMODE } from '../../consts/AMODE'; import { nodeToFsa } from '../../node-to-fsa'; import { IDirent, IStats } from '../../node/types/misc'; import { FsaNodeFs } from '../FsaNodeFs'; -import { tick, until, of } from '../../thingies'; +import { of } from '../../thingies'; import { onlyOnNode20 } from '../../__tests__/util'; import { FLAG } from '../../consts/FLAG'; +const tick = (ms: number = 1) => new Promise((r) => setTimeout(r, ms)); + +const until = async (check: () => boolean | Promise, pollInterval: number = 1) => { + do { + if (await check()) return; + await tick(pollInterval); + } while (true); +}; + const setup = (json: NestedDirectoryJSON | null = null, mode: 'read' | 'readwrite' = 'readwrite') => { const { fs: mfs, vol } = memfs({ mountpoint: json }); const dir = nodeToFsa(mfs, '/mountpoint', { mode, syncHandleAllowed: true }); diff --git a/src/thingies/index.ts b/src/thingies/index.ts index 1e14d039a..be02252a2 100644 --- a/src/thingies/index.ts +++ b/src/thingies/index.ts @@ -2,5 +2,3 @@ export * from './concurrency'; export * from './Defer'; export * from './go'; export * from './of'; -export * from './tick'; -export * from './until'; diff --git a/src/thingies/tick.ts b/src/thingies/tick.ts deleted file mode 100644 index c3979cb45..000000000 --- a/src/thingies/tick.ts +++ /dev/null @@ -1 +0,0 @@ -export const tick = (ms: number = 1) => new Promise((r) => setTimeout(r, ms)); diff --git a/src/thingies/until.ts b/src/thingies/until.ts deleted file mode 100644 index 7b7f63926..000000000 --- a/src/thingies/until.ts +++ /dev/null @@ -1,8 +0,0 @@ -import {tick} from './tick'; - -export const until = async (check: () => boolean | Promise, pollInterval: number = 1) => { - do { - if (await check()) return; - await tick(pollInterval); - } while (true); -};