On this page
event_note
Scheduling
Schedules function execution for a specific time, on a recurring interval, or using a custom scheduler function. Returns a subscription that can be paused, resumed, or canceled.
Scheduling
Scheduling decorators run functions at specific times or intervals. Backpressure controls what happens when a scheduled or invoked function cannot keep up with incoming work.
schedule / scheduleRecurring / scheduleCustom
What it is
Schedules function execution for a specific time, on a recurring interval, or using a custom scheduler function. Returns a subscription that can be paused, resumed, or canceled.
When to use it
- Cron-like tasks
- Periodic polling
- One-time delayed jobs
- Sync cleanup tasks (via
FuncSync<R>)
Async / sync support
Func<R> | Func1<T, R> | Func2<T1, T2, R> | FuncSync<R> |
|---|---|---|---|
| ✅ | ✅ | ✅ | ✅ |
API reference
| |
ScheduleMode:
oncerecurringcustom
MissedExecutionPolicy:
skipexecuteImmediatelycatchUpreschedule
Examples
Minimal
| |
Real world
| |
Best practices
- Always keep the subscription and call
cancel()when the schedule is no longer needed. - Use
maxIterationsor astopConditionto avoid runaway schedules.
Common pitfalls
- Calling the wrapped function directly throws
StateError('Scheduled functions cannot be called directly. Use start() instead.'). - Recurring schedules first run at
now + intervalunlessexecuteImmediately: trueis set. catchUpcan cause a burst of executions after a long pause.
backpressure
What it is
Controls what happens when calls arrive faster than the function can process them.
When to use it
- Streams of tasks with a slow consumer
- Load shedding
- Preventing memory exhaustion during traffic spikes
Async / sync support
Func<R> | Func1<T, R> | Func2<T1, T2, R> | FuncSync<R> |
|---|---|---|---|
| ❌ | ✅ | ✅ | ❌ |
API reference
| |
BackpressureStrategy:
drop— reject new items immediately.dropOldest— remove oldest buffered items.buffer— queue items up tobufferSize.sample— accept items probabilistically.throttle— delay execution.error— throwStateErroron overflow.
Examples
Minimal
| |
Real world
| |
Best practices
- Pair
bufferorthrottlewithmaxConcurrentto control throughput. - Use
droporsampleonly when losing work is acceptable.
Common pitfalls
- Overflow throws
StateErrorfor most strategies; messages vary by strategy. backpressureis only available onFunc1andFunc2.