Effect-TS / effect

An ecosystem of tools to build robust applications in TypeScript

Home Page:https://effect.website

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Feature Request: Enhance TestClock with Automatic Time Management

dilame opened this issue · comments

What is the problem this feature would solve?

Currently, TestClock requires manual time adjustments, making it cumbersome for testing complex asynchronous scenarios involving multiple parallel processes with varying delays.

const waitRandomTimeAndPrintCurrentTime = Effect.gen(function *(){
    const randomSleepTime = yield* Random.nextIntBetween(1000,5000);
    yield* Effect.sleep(randomSleepTime);
    const currentTime = yield* Clock.currentTimeMillis;
    yield* Console.log(currentTime);
})

const test = Effect.gen(function* () {
    yield* Effect.forkDaemon(waitRandomTimeAndPrintCurrentTime)
    yield* Effect.forkDaemon(waitRandomTimeAndPrintCurrentTime)
})

What is the feature you are proposing to solve the problem?

Enhance TestClock with automatic time management, similar to RxJS's VirtualTimeScheduler. This scheduler should have a flush() method that executes all queued actions and advances time accordingly. This feature would help create more realistic and comprehensive test scenarios without the need to manually simulate each time step.

What alternatives have you considered?

I considered using Clock.sleeps() to obtain the next scheduled event and then adjusting time to it manually. However, I could only retrieve an empty array during my tests. Maybe i did something wrong