r-lib / later

Schedule an R function or formula to run after a specified period of time.
https://r-lib.github.io/later
Other
137 stars 27 forks source link

Running an R callback function from later::BackgroundTask #162

Closed cdurden closed 2 years ago

cdurden commented 2 years ago

I am trying to write a background task that will run an R callback function whenever it completes. I believe I have followed the instructions in the vignette titled Using later from C++. In particular, I read that the execute method of my later::BackgroundTask must not call any R code, but that I can call R code from complete. However, when I call my R callback function from the complete I get a segfault. I would like to understand why this approach does not seem to work.

I have created the github repository latercallback with a simplified demo of my approach. My later::BackgroundTask subclass is contained in the file latercallback.cpp.

While experimenting with this, I also discovered that I can make the callback mechanism work by removing the comment on line 11, but I don't know why.

Any insight would be appreciated!