Skip to main content



patronum 1.7.0

import { interval } from 'patronum';
// or
import { interval } from 'patronum/interval';

interval({ timeout, start, stop })


Creates a dynamic interval with events to start, stop interval, and handle tick.


const { tick, isRunning } = interval({
  • When start is triggered, tick will be triggered each timeout ms
  • Till start is triggered, until stop is triggered, isRunning will be true
  • After stop is triggered tick won't be triggered, until start is run again


  1. timeout (number | Store<number>) - timeout for each tick run
  2. start (Event<any>) - start triggering tick. Double trigger without stop call, do nothing.
  3. stop (Event<any>) - stop triggering tick. Double trigger without start call between them, do nothing.
  4. leading (boolean) - Allows running tick when start is triggered.
  5. trailing (boolean) - Allows running tick when stop is triggered, it will be final call of tick.


  • An object of event tick and store isRunning
    • tick (Event<void) - the event is run on each timeout ms after start trigger until stop trigger
    • isRunning (Store<boolean>) - the store contains false until start is triggered, next until stop triggered the store will be true.


import { createStore, createEvent } from 'effector';
import { interval } from 'patronum';

const startCounter = createEvent();
const stopCounter = createEvent();
const $counter = createStore(0);

const { tick } = interval({
timeout: 500,
start: startCounter,
stop: stopCounter,

$counter.on(tick, (number) => number + 1);
$ => console.log('COUNTER', value));


setTimeout(() => stopCounter(), 5000);

Try it

@@trigger protocol

interval supports @@trigger protocol. It means that you can use interval whatever you can use trigger with, just do not pass start and stop options.

import { interval } from 'patronum';

trigger: interval({ timeout: 1000 }),

For example, you can use interval to refresh data in the Query from the library Farfetched using @@trigger protocol.

import { keepFresh } from '@farfetched/core';
import { interval } from 'patronum';

keepFresh(someQuery, {
// 👇 Query will be refreshed each 1000 ms
triggers: [interval({ timeout: 1000 })],