The hardware and bandwidth for this mirror is donated by dogado GmbH, the Webhosting and Full Service-Cloud Provider. Check out our Wordpress Tutorial.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]dogado.de.

mirai - Promises Integration

Promises Integration

{mirai} supplies its own as.promise() method, allowing it to be used as a promise from the promises package.

These promises are innovative, event-driven promises, developed in collaboration with Joe Cheng.

A ‘mirai’ may be piped directly using the promise pipe &...>%, which implicitly calls as.promise() on the ‘mirai’. Similarly all promise-aware functions such as promises::then() or shiny::ExtendedTask$new() which take a promise can also take a ‘mirai’ (using promises >= 1.3.0).

Alternatively, it may be converted into a promise by as.promise(), which then allows using the methods $then(), $finally() etc.

The following example outputs “hello” to the console after one second when the ‘mirai’ resolves.

library(mirai)
library(promises)

p <- mirai({Sys.sleep(1); "hello"}) %...>% cat()
p
#> <Promise [pending]>

It is possible to both access a ‘mirai’ value at $data and to use a promise for enacting a side effect (assigning the value to an environment in the example below).

library(mirai)

env <- new.env()

m <- mirai({
  Sys.sleep(1)
  "hello"
})

promises::then(m, function(x) env$res <- x)

call_mirai(m)$data
#> [1] "hello"

After returning to the top level prompt:

env$res
#> [1] "hello"

These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.
Health stats visible at Monitor.