module Data.MonadicStreamFunction.ReactHandle where
import Control.Monad.IO.Class (MonadIO, liftIO)
import Data.IORef (IORef, newIORef, readIORef, writeIORef)
import Data.MonadicStreamFunction (MSF)
import Data.MonadicStreamFunction.InternalCore (unMSF)
type ReactHandle m = IORef (MSF m () ())
reactInit :: MonadIO m => MSF m () () -> m (ReactHandle m)
reactInit :: forall (m :: * -> *). MonadIO m => MSF m () () -> m (ReactHandle m)
reactInit = forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. a -> IO (IORef a)
newIORef
react :: MonadIO m => ReactHandle m -> m ()
react :: forall (m :: * -> *). MonadIO m => ReactHandle m -> m ()
react ReactHandle m
handle = do
MSF m () ()
msf <- forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ forall a. IORef a -> IO a
readIORef ReactHandle m
handle
(()
_, MSF m () ()
msf') <- forall (m :: * -> *) a b. MSF m a b -> a -> m (b, MSF m a b)
unMSF MSF m () ()
msf ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ forall a. IORef a -> a -> IO ()
writeIORef ReactHandle m
handle MSF m () ()
msf'