Copyright | (C) 2015 Tweag I/O Limited. |
---|---|
Safe Haskell | None |
Language | Haskell2010 |
Helper module for writing event loops that mesh with R events.
Events in R are dispatched from a number of file descriptors. The R runtime maintains a list of "input handlers", essentially a set of file descriptors together with callbacks for each one, invoked whenever the file descriptor becomes available for reading. This module exports functions for dispatching on both R events and Haskell events simultaneously, using GHC.Event, which is based on epollkqueuepoll under the hood for efficient and scalable event dispatching.
Event dispatching and processing is in particular necessary for R's GUI to be responsive. For a consistent user experience, you should arrange for all GUI related events to be dispatched from a single thread, ideally the program's main thread. In fact on some platforms, most notably OS X (darwin), you must use the main thread.
Event loops can be constructed in one of two ways:
eventLoopPoll
, which uses GHC'spoll(2)
(and related syscalls) based efficient and scalable mechanisms for event dispatch;eventLoopSelect
, which uses R'sselect(2)
based mechasism.
NOTE: in GHC 7.8 and 7.10, eventLoopPoll
is currently unusable, due to
a number of functions from the event API not being exported like they were
previously.
- forIH :: Ptr InputHandler -> (InputHandler -> IO a) -> IO [a]
- forIH_ :: Ptr InputHandler -> (InputHandler -> IO ()) -> IO ()
- registerREvents :: MonadR m => EventManager -> m ([FdKey], Maybe TimeoutKey)
- eventLoopPoll :: MonadR m => m ()
- eventLoopSelect :: MonadR m => m ()
- refresh :: MonadR m => m ()
Documentation
forIH :: Ptr InputHandler -> (InputHandler -> IO a) -> IO [a] Source #
Iterate over each input handler in a chain.
forIH_ :: Ptr InputHandler -> (InputHandler -> IO ()) -> IO () Source #
Variant of forIH
that throws away the result.
registerREvents :: MonadR m => EventManager -> m ([FdKey], Maybe TimeoutKey) Source #
Register all R input handlers with the given event manager. Set an alarm to
process polled events if R_wait_usec
is non-zero. Returns keys useful for
unregistering input handlers.
eventLoopPoll :: MonadR m => m () Source #
Process events in a loop. Uses a new GHC event manager under the hood. This function should be called from the main thread. It never returns.
Currently unimplemented.
eventLoopSelect :: MonadR m => m () Source #
Process events in a loop. Uses R's select()
mechanism under the hood.
This function should be called from the main thread. It never returns.