inline-r-0.9.1: Seamlessly call R from Haskell and vice versa. No FFI required.

Copyright(C) 2015 Tweag I/O Limited.
Safe HaskellNone
LanguageHaskell2010

Language.R.Event

Description

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:

  1. eventLoopPoll, which uses GHC's poll(2) (and related syscalls) based efficient and scalable mechanisms for event dispatch;
  2. eventLoopSelect, which uses R's select(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.

Synopsis

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.

refresh :: MonadR m => m () Source #

Manually trigger processing all pending events. Useful when at an interactive prompt and no event loop is running.