Skip to content

Allow invalidateLater() to be cancelled. #4303

@mmuurr

Description

@mmuurr

I use invalidateLater() to implement custom 'polling', though there are times I want to 'bypass' the time-based invalidation (and force an invalidation sooner). Crafting a wrapper to allow that is mostly straight-forward, but in such cases I also want to clear the currently-in-flight timed invalidation (and typically reset/recreate with a fresh call to invalidateLater()).

invalidateLater() could return a zero-arg function that cancels the task (and session's registered onEnded callback, if any). Given that it currently returns invisible(NULL) and already has references to both needed clearing functions, I believe this would be:

  1. backwards-compatible, and
  2. consistent with other return-value-is-a-canceller APIs (including those used by invalidateLater() itself), and
  3. a fairly tiny code change, replacing:
    invisible()

    with:
    invisible(function() {
      timerHandle()  # clear the scheduled task
      clear_on_ended_callback()  # clear the session's onEnded callback (if any)
    })

I'm happy to generate that small PR along with tests if this is given the thumbs-up (but will save that effort if there is disapproval).

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