-- | -- Module: FRP.NetWire.IO -- Copyright: (c) 2011 Ertugrul Soeylemez -- License: BSD3 -- Maintainer: Ertugrul Soeylemez -- -- Access the rest of the universe. module FRP.NetWire.IO ( -- * IO Actions execute, executeOnce ) where import Control.Exception.Control import Control.Monad import Control.Monad.IO.Control import FRP.NetWire.Tools import FRP.NetWire.Wire -- | Execute the IO action in the input signal at every instant. -- -- Note: If the action throws an exception, then this wire inhibits the -- signal. -- -- Inhibits on exception. No feedback. execute :: MonadControlIO m => Wire m (m a) a execute = mkGen $ \_ c -> liftM (, execute) (try c) -- | Executes the IO action in the input signal and inhibits, until it -- succeeds without an exception. Keeps the result forever. -- -- Inhibits until the first result value. No feedback. executeOnce :: MonadControlIO m => Wire m (m a) a executeOnce = mkGen $ \_ c -> do mx <- try c return (mx, either (const executeOnce) constant mx)