module Eve.Internal.Async
( dispatchActionAsync
, asyncActionProvider
) where
import Eve.Internal.Actions
import Eve.Internal.AppState
import Eve.Internal.States
import Control.Concurrent
import Control.Monad
import Control.Monad.State
import Control.Lens
import Data.Typeable
dispatchActionAsync
:: (MonadIO m, HasStates base, Typeable m, Typeable base) => IO (AppT base m ()) -> ActionT base zoomed m ()
dispatchActionAsync asyncAction = liftApp $ do
mQueue <- use asyncQueue
case mQueue of
Nothing -> return ()
Just queue -> liftIO . void . forkIO $ asyncAction >>= writeChan queue
asyncActionProvider :: (MonadIO m, HasStates base, Typeable m, Typeable base) => ((AppT base m () -> IO ()) -> IO ()) -> ActionT base zoomed m ()
asyncActionProvider provider = liftApp $ do
mQueue <- use asyncQueue
case mQueue of
Nothing -> return ()
Just queue -> liftIO . void . forkIO $ provider (writeChan queue) where