Private event loops

Normally, later uses a global event loop for scheduling and running functions. However, in some cases, it is useful to create a private event loop to schedule and execute tasks without disturbing the global event loop. For example, you might have asynchronous code that queries a remote data source, but want to wait for a full back-and-forth communication to complete before continuing in your code -- from the caller's perspective, it should behave like synchronous code, and not do anything with the global event loop (which could run code unrelated to your operation). To do this, you would run your asynchronous code using a private event loop.

create_loop(autorun = NULL)





with_loop(loop, expr)



Should this event loop automatically be run when its parent loop runs? Currently, only FALSE is allowed, but in the future TRUE will be implemented and the default. Because in the future the default will change, for now any code that calls create_loop must explicitly pass in autorun=FALSE.


A handle to an event loop.


An expression to evaluate.


create_loop creates and returns a handle to a private event loop, which is useful when for scheduling tasks when you do not want to interfere with the global event loop.

destory_loop destroys a private event loop.

exists_loop reports whether an event loop exists -- that is, that it has not been destroyed.

current_loop returns the currently-active event loop. Any calls to later() or run_now() will use the current loop by default.

with_loop evaluates an expression with a given event loop as the currently-active loop.

with_temp_loop creates an event loop, makes it the current loop, then evaluates the given expression. Afterwards, the new event loop is destroyed.

global_loop returns a handle to the global event loop.

  • create_loop
  • destroy_loop
  • exists_loop
  • current_loop
  • with_temp_loop
  • with_loop
  • global_loop
Documentation reproduced from package later, version 1.0.0, License: GPL (>= 2)

Community examples

Looks like there are no examples yet.