Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider adding callback and/or message queue for sending information to a background thread #92

Open
wch opened this issue Jul 22, 2019 · 1 comment

Comments

@wch
Copy link
Member

wch commented Jul 22, 2019

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.)

@dselivanov
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants