Private event loop behaves differently when executed within block

Open
#174 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
42/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
r
Domain
backend

Research direction

Reproduce the two execution forms using later::create_loop(), later::later(), Sys.sleep(), and later::run_now(loop = tloop). Then trace how the private loop is serviced in each case and determine whether the difference is intended. Done means the behavior is explained and, if it is a bug, the relevant behavior is covered by a regression test.

Written by the indexing model from the issue text.

Description

Let's define this function and event loop:

fn <- function() print(Sys.time())
tloop <- later::create_loop()

If I execute a block of code like this, then fn gets exxecuted:

> {print(Sys.time()); later::later(fn, delay = 2, loop = tloop); Sys.sleep(5)}
[1] "2023-05-14 11:19:17 UTC"
[1] "2023-05-14 11:19:23 UTC"

But if I execute line by line (important!), I get this:

> print(Sys.time())
[1] "2023-05-14 11:21:16 UTC"
> later::later(fn, delay = 2, loop = tloop)
> Sys.sleep(5)

Why does the fn execute in first case, but not in the second case? Is this by design, or a bug?

In the second case, fn would be execueted only if 2 seconds pass and either:

  • later is invoked again
  • later::run_now(loop = tloop) is executed.
Dominant language
C++
Stars
150
Forks
31
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from r-lib/later

All issues in r-lib/later

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.