Skip to content

Reflex doesn't have a Pure Time module, Reflex.Time is impure #534

Open

Description

@parenthetical

The Reflex.Time module uses the impure PerformEvent class. As a consequence, using Reflex.Time functions for e.g. animations would lead to glitches, e.g. if multiple identical animations start simultaneously.

We should:

  • Make the impure nature of the module clear in the documentation.
  • Consider renaming the module appropriately.
  • Implement a pure version of Time.

An efficient implementation of a pure Time would need a priority queue containing "scheduled time" values. In every frame, if the queue contains a value, check the current system time T; if scheduled time <= T, fire the triggers simultaneously.

Users might also want access to a time behavior. Implementing this behavior correctly and efficiently, together with the "scheduled time" queue is somewhat tricky, but must be possible.

A minimal class could look like this:

class (Reflex t) => HasTime t m | m -> t where
  type Time t :: Type
  type PositiveTimeDelta t :: Type
  time :: Behavior t Time
  after :: PositiveTimeDelta t -> m (Event ())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions