Debian Codegraph @

man/create_loop.Rd

raw
1 % Generated by roxygen2: do not edit by hand
2 % Please edit documentation in R/later.R
3 \name{create_loop}
4 \alias{create_loop}
5 \alias{destroy_loop}
6 \alias{exists_loop}
7 \alias{current_loop}
8 \alias{with_temp_loop}
9 \alias{with_loop}
10 \alias{global_loop}
11 \title{Private event loops}
12 \usage{
13 create_loop(parent = current_loop())
14
15 destroy_loop(loop)
16
17 exists_loop(loop)
18
19 current_loop()
20
21 with_temp_loop(expr)
22
23 with_loop(loop, expr)
24
25 global_loop()
26 }
27 \arguments{
28 \item{parent}{The parent event loop for the one being created. Whenever the
29 parent loop runs, this loop will also automatically run, without having to
30 manually call \code{\link{run_now}()} on this loop. If \code{NULL}, then
31 this loop will not have a parent event loop that automatically runs it; the
32 only way to run this loop will be by calling \code{\link{run_now}()} on this
33 loop.}
34
35 \item{loop}{A handle to an event loop.}
36
37 \item{expr}{An expression to evaluate.}
38 }
39 \description{
40 Normally, later uses a global event loop for scheduling and running
41 functions. However, in some cases, it is useful to create a \emph{private}
42 event loop to schedule and execute tasks without disturbing the global event
43 loop. For example, you might have asynchronous code that queries a remote
44 data source, but want to wait for a full back-and-forth communication to
45 complete before continuing in your code -- from the caller's perspective, it
46 should behave like synchronous code, and not do anything with the global
47 event loop (which could run code unrelated to your operation). To do this,
48 you would run your asynchronous code using a private event loop.
49 }
50 \details{
51 \code{create_loop} creates and returns a handle to a private event loop,
52 which is useful when for scheduling tasks when you do not want to interfere
53 with the global event loop.
54
55 \code{destroy_loop} destroys a private event loop.
56
57 \code{exists_loop} reports whether an event loop exists -- that is, that it
58 has not been destroyed.
59
60 \code{current_loop} returns the currently-active event loop. Any calls to
61 \code{\link{later}()} or \code{\link{run_now}()} will use the current loop by
62 default.
63
64 \code{with_loop} evaluates an expression with a given event loop as the
65 currently-active loop.
66
67 \code{with_temp_loop} creates an event loop, makes it the current loop, then
68 evaluates the given expression. Afterwards, the new event loop is destroyed.
69
70 \code{global_loop} returns a handle to the global event loop.
71 }