as.promise.mirai_map: Make mirai_map Promise

View source: R/promises.R

as.promise.mirai_mapR Documentation

Make mirai_map Promise

Description

Creates a 'promise' from a 'mirai_map'.

Usage

## S3 method for class 'mirai_map'
as.promise(x)

Arguments

x

an object of class 'mirai_map'.

Details

This function is an S3 method for the generic as.promise() for class 'mirai_map'.

Requires the promises package.

Allows a 'mirai_map' to be used with the promise pipe ⁠%...>%⁠, which schedules a function to run upon resolution of the entire 'mirai_map'.

The implementation internally uses promises::promise_all(). If all of the promises were successful, the returned promise will resolve to a list of the promise values; if any promise fails, the first error to be encountered will be used to reject the returned promise.

Value

A 'promise' object.

Examples


library(promises)

with(daemons(1), {
  mp <- mirai_map(1:3, function(x) { Sys.sleep(1); x })
  p <- as.promise(mp)
  print(p)
  p %...>% print
  mp[.flat]
})


mirai documentation built on April 4, 2025, 12:27 a.m.