RLesur / crrri

A Chrome Remote Interface written in R

Home Page:https://rlesur.github.io/crrri/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Use private event loop where necessary

cderv opened this issue · comments

This seems important to not conflict with other later loop while in !async mode like maybe in wait function.

private event loop are used in chromote and also will be pagedown::chrome_print

Here's a summary of how chromote uses a private event loop. I think you should be able to adapt it for crrri.

With this setup, whenever you call run_now() (on the main/global loop), or when the R console is idle, the behavior will be essentially the same as the case where no private loop is used. However, it is also possible to run the private loop by itself, with something like run_now(loop = private_loop), and that lets you wait for something to happen without accidentally running a callback that belongs to someone else.

Note that currently when Chromote schedules the private loop to be run from the main loop, it does so every .01 seconds. This is not ideal, and in the future we would like to make it unnecessary by providing an option when the private loop is created.

Chromote also has a function called synchronize, which will block until a promise resolves. Note that this code is a bit experimental. Also, much of the complexity is present because it tries to gracefully handle interrupts.
https://github.com/rstudio/chromote/blob/f53a70b/R/synchronize.R#L99-L148

Look also at new feature of private loop autorun rstudio/chromote#24