Can anyone give me an explanation of a promise object in R? I'm still new to R. So thanks in advance for keeping it simple (if possible).
I couldn't find a brief description nor in literature neither at web.
The Promise object represents the eventual completion (or failure) of an asynchronous operation and its resulting value. To learn about the way promises work and how you can use them, we advise you to read Using promises first.
A promise is a placeholder object for the eventual result (or error) of an asynchronous operation. This function is not generally needed to carry out asynchronous programming tasks; instead, it is intended to be used mostly by package authors who want to write asynchronous functions that return promises.
You are getting [object Promise] as value because you are calling an asynchronous function inside a synchronous code. This means the synchronous code runs line by line giving no room for asynchronous code to wait and give a response (the promise).
A Promise is an object representing the eventual completion or failure of an asynchronous operation. Since most people are consumers of already-created promises, this guide will explain consumption of returned promises before explaining how to create them.
Promise objects are used within packages to make objects available to users without loading them into the memory. Unfortunately, it is not possible to determine if an object is a promise object, nor it is possible to figure out the environment in which it was created. For example : You can create a promise object to delay evaluation of a variable until it is (first) needed. You can do it using delayedAssign function.
x <- 1
y <- 2
z <- 3
delayedAssign("v", c(x, y, z))
x <- 5
v
#[1] 5 2 3
Reference : http://130.132.212.207/mediawiki/images/0/09/R_in_a_Nutshell.pdf
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With