Closed skannan007 closed 1 year ago
I found this solution from old posts, just added below code at the end of your websocket r program, after this I can run from command-line interface or shell script. while (TRUE) { if (ws$readyState() %in% c(2,3)) { break } else {later::run_now(1L)} }
When running from Rstudio UI: After ws <- WebSocket$new line execution, R listens for ws$onOpen ws$onMessage events. And in parallel runs rest of the code outside ws$onOpen ws$onMessage etc, till the end.
When running from unix shell script: Using below R commands [ Rscript /path/to/myRprogram .R (OR) R -f /path/to/myRprogram .R] After ws <- WebSocket$new line execution, R does NOT listen for ws$onOpen ws$onMessage events. It just runs rest of the code outside the functions ws$onOpen ws$onMessage etc, till the end and completely stops the program execution.