Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Never clock #297

Merged
merged 1 commit into from
Mar 25, 2024
Merged

Add Never clock #297

merged 1 commit into from
Mar 25, 2024

Conversation

ners
Copy link
Contributor

@ners ners commented Mar 9, 2024

As seen in: https://github.com/ners/rhine-linux/blob/master/kitchen-sink/Main.hs

Some clocks may fail to initialise (e.g. because they depend on missing external resources), but we would like to recover gracefully by replacing them with a clock that never ticks.

And so we introduce a clock that never ticks, but can produce anything:

initFallibleClock
    :: forall m cl
     . ( Clock m cl
       , MonadIO m
       , MonadCatch m
       , Time cl ~ Time Never
       )
    => cl
    -> RunningClockInit m (Time cl) (Tag cl)
initFallibleClock cl = catchAll (initClock cl) $ const $ initClock Never <&> first (>>^ second absurd)

@turion
Copy link
Owner

turion commented Mar 11, 2024

Thanks a lot! This is a useful addition.

This clock does not actually run in MonadIO because it is modelled after FRP.Rhine.Clock.Realtime.Busy, which runs in IO. We should probably make both of them MonadIO in the future.

I agree, we should, and indeed I think Never can already be in MonadIO. Busy can be changed later.

@turion
Copy link
Owner

turion commented Mar 11, 2024

Have you seen #287? I think this will interplay really nicely with Never!

@turion turion merged commit 7f1fdb9 into turion:master Mar 25, 2024
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants