A library for task-scheduling in Dart. Exports a Task class that returns Streams, with a number of versatile options to customize how Tasks are run.

Tasks take a Function (and a corresponding List argument) and run them asynchronously on a number of triggers. All methods return Streams, because of their versatility: Streams can be listened, canceled, or converted to other types.

Methods take inspiration from Quartz Scheduler.


A (very) simple usage example:

import 'package:pendulum/pendulum.dart';

void main() async {
  var task = Task<String>((List args) {
    return 'Simple process!';
  }, []);
  var task2 = Task<String>((List args) {
    return 'Delayed process!';
  }, []);
  var task3 = Task<String>((List args) {
    return 'Repeated process!';
  }, []);
  var watch = Stopwatch();

  // Simple process and listen.
  task.process().listen((var data) {

  // Process after a delay of 5 seconds.
  task2.processAfter(Duration(seconds: 5)).listen((var data) {

  await Future.delayed(Duration(seconds: 10));

  // Repeatedly process every 5 seconds for 20 seconds.
      .repeatIntervalFor(Duration(seconds: 20), Duration(seconds: 5))
      .listen((var data) {

This is just the start of the features of Pendulum. To see all the methods and triggers, check out the API reference.

Simulated Tasks

Testing Pendulum can be a pain if you're using Tasks with DateTime arguments, because you have to wait for the DateTime to be reached to test. My solution to this problem is SimulatedTask:

  • Simulated Task uses a provided DateTime instead of
  • You can 'fast-forward' to any point in time that you want using setNow(DateTime arg)

This is obviously an imperfect solution, and I'm welcome to suggestions as to alternatives.

Partners in Crime

While Pendulum works fine all on its own, there are some packages that can enhance its functionality. A few of them are listed below:

  • RxDart
    • Library for Stream extensions.
    • Can be used to enhance processor methods
  • Instant
    • Library for DateTime manipulation.
    • Many Pendulum triggers involve DateTimes
    • Can be used to adjust for timezones
  • Isolate
    • Library for isolate management.
    • While Pendulum runs async, one isolate might not be able to handle all the tasks.
    • Using the isolate load_balancer class to run tasks could thus save CPU.

Features and bugs

Please file feature requests and bugs at the issue tracker.

This package and its contents are subject to the terms of the Mozilla Public License, v. 2.0.
© 2019 Aditya Kishore


A dynamic, Stream-based API for job scheduling in Dart, capable of processing on different triggers.