Skip to content

Private event loop behaves differently when executed within block #174

Open
@DavorJ

Description

@DavorJ

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions