Rev 78076 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
% File src/library/base/man/taskCallbackManager.Rd% Part of the R package, https://www.R-project.org% Copyright 1995-2020 R Core Team% Distributed under GPL 2 or later\name{taskCallbackManager}\alias{taskCallbackManager}\title{Create an R-level Task Callback Manager}\description{This provides an entirely \R-language mechanismfor managing callbacks or actions that are invoked atthe conclusion of each top-level task. Essentially,we register a single \R function from this managerwith the underlying, nativetask-callback mechanism and this function handles invoking the otherR callbacks under the control of the manager.The manager consists of a collection of functions that access sharedvariables to manage the list of user-level callbacks.}\usage{taskCallbackManager(handlers = list(), registered = FALSE,verbose = FALSE)}\arguments{\item{handlers}{this can be a list of callbacks in which each elementis a list with an element named \code{"f"}which is a callback function, and an optionalelement named \code{"data"} which is the 5-th argument to besupplied to the callback when it is invoked.Typically this argument is not specified, and one uses \code{add} toregister callbacks after the manager is created.}\item{registered}{a logical value indicating whetherthe \code{evaluate} function has already been registeredwith the internal task callback mechanism.This is usually \code{FALSE} andthe first time a callback is addedvia the \code{add} function, the\code{evaluate} function is automatically registered.One can control when the function is registeredby specifying \code{TRUE} for this argumentand calling \code{\link{addTaskCallback}} manually.}\item{verbose}{a logical value, which if \code{TRUE},causes information to be printed to the consoleabout certain activities this dispatch manager performs.This is useful for debugging callbacks and the handleritself.}}\value{A \code{\link{list}} containing 6 functions:\item{\code{add()}}{register a callback with this manager, giving thefunction, an optional 5-th argument, an optional nameby which the callback is stored in the list,and a \code{register} argument which controls whetherthe \code{evaluate} function is registered with the internalC-level dispatch mechanism if necessary.}\item{\code{remove()}}{remove an element from the manager's collectionof callbacks, either by name or position/index.}\item{\code{evaluate()}}{the \sQuote{real} callback function that is registeredwith the C-level dispatch mechanism and which invokes each of theR-level callbacks within this manager's control.}\item{\code{suspend()}}{a function to set the suspend stateof the manager. If it is suspended, none of the callbacks will beinvoked when a task is completed. One sets the state by specifyinga logical value for the \code{status} argument.}\item{\code{register()}}{a function to register the \code{evaluate}function with the internal C-level dispatch mechanism. This isdone automatically by the \code{add} function, but can be calledmanually.}\item{\code{callbacks()}}{returns the list of callbacks being maintainedby this manager.}}\seealso{\code{\link{addTaskCallback}},\code{\link{removeTaskCallback}},\code{\link{getTaskCallbackNames}} and the reference.}\references{Duncan Temple Lang (2001)\emph{Top-level Task Callbacks in R}, % TaskHandlers.tex is in R-dev-web svn\url{https://developer.r-project.org/TaskHandlers.pdf}}\examples{# create the managerh <- taskCallbackManager()# add a callbackh$add(function(expr, value, ok, visible) {cat("In handler\n")return(TRUE)}, name = "simpleHandler")# look at the internal callbacks.getTaskCallbackNames()# look at the R-level callbacksnames(h$callbacks())removeTaskCallback("R-taskCallbackManager")}\keyword{environment}