later
later copied to clipboard
Consider adding callback and/or message queue for sending information to a background thread
Currently, the later::later()
C function can be used by a background thread to schedule code to run on the main R thread. However, we don't have a way for the main thread to safely pass messages to the background thread, or to schedule functions to run on the background thread. This is a pattern that's used in httpuv and will be used in websocket. We should consider adding functionality to later that makes it easier to do these things.
(Note: there is the BackgroundThread
class, but that launches a thread, runs a function on the new thread, and when that function finishes, it schedules a function to run on the main R thread and then closes the thread. This is fine for threads that do one task and then stop, but it isn't usable for threads that need to persist, like ones in httpuv and websocket that handle network I/O.)
Hi @wch. Do you have any tips on how to do that using current version of the later
package? In my case background thread should handle I/O - answer heartbeats and send data from R.