async {background}R Documentation

Asynchronous input callbacks

Description

async.add registers a new asynchronous callback

async.rm removes an asynchronous handler

Usage

async.add(fd, callback = function(h, data) async.rm(h), data = NULL)
async.rm(handler)

Arguments

fd

file descriptor (of any kind including sockets or pipes) which will trigger a callback

callback

callback function

data

any user data that will be passed as the second argument to the callback (after the handler)

handler

handler as returned by async.fd or passed as the first argument to the callback function

Details

Asynchronous callbacks trigger when R is idle and read activity is signalled on the file descriptor. The activity can be incoming connection, data or similar.

It is important that the callback resolves the reason for the trigger or removes the handler. Failing to do so will result in infinite calling of the callback handler.

Value

async.add returns the (opaque) handler object

async.rm return TRUE

Author(s)

Simon Urbanek

Examples

## Not run: 
   future = function(expr) {
      p = parallel::mcparallel(expr)
      async.add(p$fd[1], function(h, p) {
         async.rm(h)
         print(parallel::mccollect(p)[[1]])
      }, p)
      invisible(p)
   }

   future({ Sys.sleep(5); "done!" })
   ## in 5 seconds you'll see an output

## End(Not run)

[Package background version 0.1-1 Index]