EVOLUTION-MANAGER
Edit File: promise.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Create a new promise object</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for promise {promises}"><tr><td>promise {promises}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Create a new promise object</h2> <h3>Description</h3> <p><code>promise()</code> creates a new promise. 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. </p> <h3>Usage</h3> <pre> promise(action) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>action</code></td> <td> <p>A function with signature <code style="white-space: pre;">function(resolve, reject)</code>, or a one-sided formula. See Details.</p> </td></tr> </table> <h3>Details</h3> <p>The <code>action</code> function should be a piece of code that returns quickly, but initiates a potentially long-running, asynchronous task. If/when the task successfully completes, call <code>resolve(value)</code> where <code>value</code> is the result of the computation (like the return value). If the task fails, call <code>reject(reason)</code>, where <code>reason</code> is either an error object, or a character string. </p> <p>It's important that asynchronous tasks kicked off from <code>action</code> be coded very carefully–in particular, all errors must be caught and passed to <code>reject()</code>. Failure to do so will cause those errors to be lost, at best; and the caller of the asynchronous task will never receive a response (the asynchronous equivalent of a function call that never returns, i.e. hangs). </p> <p>The return value of <code>action</code> will be ignored. </p> <h3>Value</h3> <p>A promise object (see <code><a href="then.html">then</a></code>). </p> <h3>Examples</h3> <pre> # Create a promise that resolves to a random value after 2 secs p1 <- promise(function(resolve, reject) { later::later(~resolve(runif(1)), delay = 2) }) p1 %...>% print() # Create a promise that errors immediately p2 <- promise(~{ reject("An error has occurred") }) then(p2, onFulfilled = ~message("Success"), onRejected = ~message("Failure") ) </pre> <hr /><div style="text-align: center;">[Package <em>promises</em> version 1.1.1 <a href="00Index.html">Index</a>]</div> </body></html>