Using promises
Last updated
Last updated
As explained in , R is single-threaded.
While our Shiny toolchain optimizes your application by running multiple R processes, using promises will maximize your performance far greater than our balancing between multiple R processes.
Synchronus code executes linearly. The following reads a CSV from the included URL.
Before a
can be assigned the value of 3
, R will execute an HTTP request to http://example.com/data/data.csv
, download the CSV, and store it in the variable value
. The R process is blocked until this is completed. There is no reason to wait for the CSV to complete downloading before continuing with the rest of your application's code, in particular because network functions can be offloaded to the operating system's event handler (libuv).
The above will download the CSV in a non-blocking manner, meaning that a
will be assigned 3 even if read.csv
hasn't completed yet.
Asynchronous programming will execute an instruction, designated as asynchronous by the promise
keyword, in a different thread, without waiting for it's result. You can offload long-running operations to a subsidiary R thread spawned by the promise library.
If you're processing CSVs, executing long-running code in your R Shiny app, you should use promises to speed up your application.
The following tutorials detail how to develop asynchronous R application.