on 5af55e5 help sign in
38 lines 2.0 kB history raw
1-- | This module defines 'TriggerEvent', which describes actions that may create
2-- new 'Event's that can be triggered from 'IO'.
3{-# LANGUAGE FlexibleInstances #-}
4{-# LANGUAGE FunctionalDependencies #-}
5{-# LANGUAGE MultiParamTypeClasses #-}
6{-# LANGUAGE UndecidableInstances #-}
7module Reflex.TriggerEvent.Class
8 ( TriggerEvent (..)
9 ) where
11import Reflex.Class
13import Control.Monad.Reader
15--TODO: Shouldn't have IO hard-coded
16-- | 'TriggerEvent' represents actions that can create 'Event's that can be
17-- triggered by 'IO' actions.
18class Monad m => TriggerEvent t m | m -> t where
19 -- | Create a triggerable 'Event'. Whenever the resulting function is called,
20 -- the resulting 'Event' will fire at some point in the future. Note that
21 -- this may not be synchronous.
22 newTriggerEvent :: m (Event t a, a -> IO ())
23 -- | Like 'newTriggerEvent', but the callback itself takes another callback,
24 -- to be invoked once the requested 'Event' occurrence has finished firing.
25 -- This allows synchronous operation.
26 newTriggerEventWithOnComplete :: m (Event t a, a -> IO () -> IO ()) --TODO: This and newTriggerEvent should be unified somehow
27 -- | Like 'newTriggerEventWithOnComplete', but with setup and teardown. This
28 -- relatively complex type signature allows any external listeners to be
29 -- subscribed lazily and then removed whenever the returned 'Event' is no
30 -- longer being listened to. Note that the setup/teardown may happen multiple
31 -- times, and there is no guarantee that the teardown will be executed
32 -- promptly, or even at all, in the case of program termination.
33 newEventWithLazyTriggerWithOnComplete :: ((a -> IO () -> IO ()) -> IO (IO ())) -> m (Event t a)
35instance TriggerEvent t m => TriggerEvent t (ReaderT r m) where
36 newTriggerEvent = lift newTriggerEvent
37 newTriggerEventWithOnComplete = lift newTriggerEventWithOnComplete
38 newEventWithLazyTriggerWithOnComplete = lift . newEventWithLazyTriggerWithOnComplete