Skip to content

Pausable / Resumable interval #91

Description

@geferon

Feature Description

An interval that can start paused with a parameter, that can be started with a method (such as the existing destroy) that can also be resumed at any point with a separate method, or restarted.

Use Case and Justification

Currently, although the interval implementation is nice, it only starts as soon as it's created which might not be ideal, and you can only 'stop' it by destroying it, making it a one time use feature.

Proposed Solution or API

const polling = interval(() => {
  console.log('interval called');
}, { start: false }); // Do not immediately start
// Although VueUse uses immediately to tell the interval if it should start as soon as it's created or not, as that's the default
// behaviour with the current implementation, and 'immediate' instead calls the method as soon as it starts,
// perhaps it would be nice to have an option to specify it not to start as soon as it's created
// reference: https://vueuse.org/shared/useInterval/

polling.start(); // Method to start/continue
polling.pause(); // Method to pause/stop
polling.active(); // Signal that returns if it's currently active or not

// Perhaps also have it like the VueUse implementation where
polling.counter() // Incremental signal that increments every time it gets called
polling.reset() // Resets the counter to 0

Considered Alternatives

No response

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions