| 42333 |
ripley |
1 |
% File src/library/base/man/taskCallbackManager.Rd
|
| 68948 |
ripley |
2 |
% Part of the R package, https://www.R-project.org
|
| 88574 |
hornik |
3 |
% Copyright 1995-2025 R Core Team
|
| 42333 |
ripley |
4 |
% Distributed under GPL 2 or later
|
|
|
5 |
|
| 17067 |
duncan |
6 |
\name{taskCallbackManager}
|
| 56186 |
murdoch |
7 |
\alias{taskCallbackManager}
|
| 50821 |
ripley |
8 |
\title{Create an R-level Task Callback Manager}
|
| 20029 |
duncan |
9 |
\description{
|
| 78539 |
ripley |
10 |
This provides an entirely \R-language mechanism
|
| 20029 |
duncan |
11 |
for managing callbacks or actions that are invoked at
|
|
|
12 |
the conclusion of each top-level task. Essentially,
|
| 78539 |
ripley |
13 |
we register a single \R function from this manager
|
| 20029 |
duncan |
14 |
with the underlying, native
|
|
|
15 |
task-callback mechanism and this function handles invoking the other
|
|
|
16 |
R callbacks under the control of the manager.
|
|
|
17 |
The manager consists of a collection of functions that access shared
|
|
|
18 |
variables to manage the list of user-level callbacks.
|
|
|
19 |
}
|
| 17067 |
duncan |
20 |
\usage{
|
| 30912 |
ripley |
21 |
taskCallbackManager(handlers = list(), registered = FALSE,
|
|
|
22 |
verbose = FALSE)
|
| 17067 |
duncan |
23 |
}
|
|
|
24 |
\arguments{
|
|
|
25 |
\item{handlers}{this can be a list of callbacks in which each element
|
|
|
26 |
is a list with an element named \code{"f"}
|
|
|
27 |
which is a callback function, and an optional
|
|
|
28 |
element named \code{"data"} which is the 5-th argument to be
|
|
|
29 |
supplied to the callback when it is invoked.
|
|
|
30 |
Typically this argument is not specified, and one uses \code{add} to
|
|
|
31 |
register callbacks after the manager is created.}
|
|
|
32 |
\item{registered}{a logical value indicating whether
|
|
|
33 |
the \code{evaluate} function has already been registered
|
|
|
34 |
with the internal task callback mechanism.
|
| 61433 |
ripley |
35 |
This is usually \code{FALSE} and
|
| 17067 |
duncan |
36 |
the first time a callback is added
|
|
|
37 |
via the \code{add} function, the
|
|
|
38 |
\code{evaluate} function is automatically registered.
|
|
|
39 |
One can control when the function is registered
|
|
|
40 |
by specifying \code{TRUE} for this argument
|
|
|
41 |
and calling \code{\link{addTaskCallback}} manually.
|
|
|
42 |
}
|
|
|
43 |
\item{verbose}{a logical value, which if \code{TRUE},
|
|
|
44 |
causes information to be printed to the console
|
|
|
45 |
about certain activities this dispatch manager performs.
|
|
|
46 |
This is useful for debugging callbacks and the handler
|
|
|
47 |
itself.
|
|
|
48 |
}
|
|
|
49 |
}
|
|
|
50 |
\value{
|
| 76364 |
maechler |
51 |
A \code{\link{list}} containing 6 functions:
|
| 80914 |
hornik |
52 |
\item{add()}{register a callback with this manager, giving the
|
| 17067 |
duncan |
53 |
function, an optional 5-th argument, an optional name
|
| 27625 |
ripley |
54 |
by which the callback is stored in the list,
|
| 17067 |
duncan |
55 |
and a \code{register} argument which controls whether
|
|
|
56 |
the \code{evaluate} function is registered with the internal
|
|
|
57 |
C-level dispatch mechanism if necessary.}
|
| 80914 |
hornik |
58 |
\item{remove()}{remove an element from the manager's collection
|
| 17067 |
duncan |
59 |
of callbacks, either by name or position/index.}
|
| 80914 |
hornik |
60 |
\item{evaluate()}{the \sQuote{real} callback function that is registered
|
| 17067 |
duncan |
61 |
with the C-level dispatch mechanism and which invokes each of the
|
| 27625 |
ripley |
62 |
R-level callbacks within this manager's control.}
|
| 80914 |
hornik |
63 |
\item{suspend()}{a function to set the suspend state
|
| 55555 |
ripley |
64 |
of the manager. If it is suspended, none of the callbacks will be
|
|
|
65 |
invoked when a task is completed. One sets the state by specifying
|
| 17067 |
duncan |
66 |
a logical value for the \code{status} argument.
|
|
|
67 |
}
|
| 80914 |
hornik |
68 |
\item{register()}{a function to register the \code{evaluate}
|
| 55555 |
ripley |
69 |
function with the internal C-level dispatch mechanism. This is
|
| 17067 |
duncan |
70 |
done automatically by the \code{add} function, but can be called
|
|
|
71 |
manually.}
|
| 80914 |
hornik |
72 |
\item{callbacks()}{returns the list of callbacks being maintained
|
| 76364 |
maechler |
73 |
by this manager.}
|
| 17067 |
duncan |
74 |
}
|
|
|
75 |
\seealso{
|
| 30912 |
ripley |
76 |
\code{\link{addTaskCallback}},
|
|
|
77 |
\code{\link{removeTaskCallback}},
|
| 76364 |
maechler |
78 |
\code{\link{getTaskCallbackNames}} and the reference.
|
|
|
79 |
}
|
|
|
80 |
\references{
|
| 88574 |
hornik |
81 |
\bibshow{R:Temple_Lang:2001b}
|
| 17067 |
duncan |
82 |
}
|
|
|
83 |
\examples{
|
| 30915 |
ripley |
84 |
# create the manager
|
|
|
85 |
h <- taskCallbackManager()
|
| 17067 |
duncan |
86 |
|
| 30915 |
ripley |
87 |
# add a callback
|
|
|
88 |
h$add(function(expr, value, ok, visible) {
|
| 47616 |
ripley |
89 |
cat("In handler\n")
|
|
|
90 |
return(TRUE)
|
|
|
91 |
}, name = "simpleHandler")
|
| 17067 |
duncan |
92 |
|
| 30915 |
ripley |
93 |
# look at the internal callbacks.
|
|
|
94 |
getTaskCallbackNames()
|
| 17067 |
duncan |
95 |
|
| 30915 |
ripley |
96 |
# look at the R-level callbacks
|
| 41607 |
ripley |
97 |
names(h$callbacks())
|
| 30915 |
ripley |
98 |
|
|
|
99 |
removeTaskCallback("R-taskCallbackManager")
|
| 17067 |
duncan |
100 |
}
|
|
|
101 |
\keyword{environment}
|