repeatPublish()
Publish messages to a topic on a recurring schedule.
Signature
ts
function repeatPublish<T>(
topicRef: Topic<T>,
valueOrFactory: T | (() => T),
opts: RepeatPublishOptions,
): RepeatHandleParameters
| Parameter | Type | Description |
|---|---|---|
topicRef | Topic<T> | The topic to publish to. |
valueOrFactory | `T | (() => T)` |
opts | RepeatPublishOptions | Scheduling configuration. |
Returns
RepeatHandle — cancel() to stop, count store for reactive tracking.
Basic Usage
ts
// Publish every 5 seconds
const handle = repeatPublish(myTopic, () => ({ type: 'heartbeat', ts: Date.now() }), {
every: 5000,
limit: 100,
});
// Publish on cron schedule
const handle = repeatPublish(myTopic, { type: 'daily-report' }, {
cron: '0 9 * * *', // 9am daily
});
// Cancel
handle.cancel();Options / Behavior Details
- Interval mode: Set
everyto publish at fixed intervals (ms). - Cron mode: Set
cronto publish on a cron schedule. Uses the library's built-in cron parser (parseCron/matchesCron). Checks every 60s by default. - Limit: Set
limitto stop after N publications. 0 = unlimited. - Dedup: Set
dedupKeyto prevent duplicate publications within the topic's dedup window.